Interview Question in Hibernate


 

Interview Question :: Distinguish between transient and detached objects?

How does Hibernate distinguish between transient (i.e. newly instantiated) and detached objects?

by ksk
VoteNowAnswers to "Distinguish between transient and detached objects?"

  1. Hibernate uses the "version" property, if there is one.
  2. If not uses the identifier value. No identifier value means a new object. This does work only for Hibernate managed surrogate keys. Does not work for natural keys and assigned (i.e. not managed by Hibernate) surrogate keys.
  3. Write your own strategy with Interceptor.isUnsaved().
by ksk