There are so many persistant classes with the identity property (primary
key) being the only feasible identifier. To be exact, only classes whose
tables have an additional unique constraint allow for safely using other
properties than the identity for equals/hashCode.
Unless I do misunderstand the matter, I have only two choices for about
99% of my persistant classes:
- using self assigned identities (primary keys) and assign them before
using the entity in a collection.
- using database assigned identites and forcing early assignment by
session.save().
Any other choices?
Regards,
Andreas |