Hibernate Tutorial 23 - Understanding State Changes

preview_player
Показать описание
We'll understand some of the different ways in which entity objects change from one state to another.
Рекомендации по теме
Комментарии
Автор

Awesome work Koushik!
I just wanted to add what I am seeing in Hibernate v4.
The detach state is after the session commit and not truly session close. It may not make sense logically, but you could still begin a new session transaction (after transaction commit) and commit again before closing and still save the updates without an explicit save.
Bottom line: As long as the session transaction is active, the object is persisted.

tomifying
Автор

Short and precise..! More than awesome

vimalalwaysrocks
Автор

Is there anything about object state after the transaction is commited and before the session is closed. Video says that once the session in closed the object becomes detached, but it seems it is being detached before session is closed and just after the transaction is commited. Can you clear it ?
e.g.
session.beginTransaction();
session.update(obj); //this update will reflect as its in persistent state

session.update(obj); // here session is not closed but object doesn't seem to be in persistent stage since this update won't reflect in DB
session.close(obj);

subashp
Автор

if you will change the user object value before session.close() but after getTransaction().commit() then also the object will come into the detached state.

birthareshubham