Monday, September 17, 2007

Hibernate Notes

Here's some Hibernate notes for beginners out there. I've been facing lots of troubles dealing with Hibernate. I hope my notes would be short and clear enough so that you guys could save some time instead of looking for answers in the thick book!

1) Don't get confused with Flush Session & Commit Transaction
I used to have a wrong concept that flush session usually means data is already sync from Hibernate Session to the Database and everything cannot be roll back anymore! This is obviously wrong! Both are irrelevant with each other in fact! Even tough flush session would sync everything from Hibernate Session to the Database, however if the unit of work is within a transaction scope, the developer should trigger a commit so that everything can be committed!

2) Session Save will assign an identifier value to the corresponding saved object
Calling hibernate session save() will not only persist your pojo, but will also assign an identifier to that pojo according to the Hibernate Mapping. The identifier assignment will not be that late until database-session sync process happen.