|
It would be great if Hibernate would provide a guarantee not to add an entity to a persistent set until all its fields have been initialized. Without that guarantee, the only viable option for equals / hashCode is to inherit from java.lang.Object, since there is no state in the object which can be considered immutable. (Or an application can assign a primary key manually rather than letting Hibernate manage the primary key, and use that for equals / hashCode.)
The recommendation to use a business key for equals / hashCode (as given in the documentation, on the hibernate wiki, and in "Java Persistence with Hibernate") implies that Hibernate has such a guarantee. If so, it would be nice to make that guarantee explicit in the documentation, and fix this bug. If not, then this bug can be closed as invalid, but the documentation should recommend against overriding equals and hashCode, and perhaps Hibernate could warn / complain if it finds an entity which does override equals / hashCode.
|