Hibernate (Java) Question:

Download Job Interview Questions and Answers PDF

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

Hibernate Interview Question
Hibernate Interview Question

Answer:

" Hibernate uses the version property, if there is one.
" 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.
" Write your own strategy with Interceptor.isUnsaved().

Download Hibernate Interview Questions And Answers PDF

Previous QuestionNext Question
What are the pros and cons of detached objects?What is the difference between the session.get() method and the session.load() method?