Is there a way to prevent duplicate data entry with hibernate on entities that have auto generated primary key?
To be more specific, i have a persistent object in the database and have a transient object (not inserted to the database yet) and those two objects are same with respect to equals and hashcode methods. But, since the id of the entity class of those objects is annotated with generated value annotation, hibernate still creates a new instance for the transient object in the database. As a result the database has duplicate entries (with respect to equals and hashcode methods) with different primary keys.
Yes, I know if I make the PK not auto generated, of if I use UUID, then i would achieve my goal. But I just wanna ask why equals and hashcode methods do not work for the entities with auto generated primary key? Or am i doing something wrong?