How hibernate session works
I have some kind of trivial queries in Hibernate.
If I assume there are two instances running and each is using its own hibernate session. If one session inserts data into DB and the second session tries to retrieve the new data, will it be able to get that data?
I have set the primary key to be generated by 开发者_Python百科a DB sequence. So I create an instance and call save() but do not commit the transaction. I am still able to get the ID of that instance. Is there a DB call happening at that moment or how does hibernate maintains its session?
yes, once the data is committed to the DB; this does depend on the isolation level configured on the transaction
Yes, it will be something like
select nextval('MY_SEQUENCE');
this will be the id set to the entity; so, you have an id even if the transaction is not committed yet.
This article is worth a read.
精彩评论