Although I've been Hibernating for a couple of years now, it seems there is always more to know. I'm a big fan of hibernate as its allowed me to apply what I learned long ago in all my OO classes w/ CRC cards. It really is possible to put Domain Model Programming into practice. Okay, so why am I writing about it today? Because I finally looked at the source to see how it does change detection. Any object loaded by HIbernate, is "watched" by hibernate for changes. I knew this, but didn't really know how it works. So, from my brief look at the code, heres how it goes AFAIK
- You load objects via load, get, query, whatever
- Hibernate puts these objects in its session cache (a hashmap)
- Hibernate uses the key of the object and the class to as the key
- When sess.flush is called (either explicitly or because tx is finished or a query is executed)
- Hibernate goes throught its identitymap of object
- Check out the FlushEventListener class for details
- The EntityEntry for the object is found
- Dirty check takes place against the EntityEntry. Each EntityEntry has the loadedState of an object, which appears to be an array of simple properties
- Update is scheduled if necessary
I initialially thought hib did all this via CGLIB. Appears I was incorrect. Also, if you think your equals methods are involved in this evaluation, that appears to not be true either.
Cheers, long live hibernate
--James
No comments:
Post a Comment