Models Inc. / HibernateObjectModelModels Inc. / HibernateObjectModel

This is the third entry in a series that is to become Databinder 101, an introductory text for the toolkit.


Happily, IModel’s detach logic provides an answer to the problem of carrying Hibernate entities between web requests. If we discard our references to the entities before the session ends, and reload them before use in a new session, it’s almost like we had the same object all along.

Almost. Any changes that weren’t persisted to the database will be undone. The programmer must either commit changes (as done by default in DataForm.onSubmit()) or let them evaporate. This isn’t so bad really, compared to practically every Web application design, but it is a little grating. Future versions of Databinder will attempt Hibernate sessions that span requests, but until then we have to think in terms of committing changes at every request.

With that caveat behind us, we can use HibernateObjectModel as our good ship entity-pop. As long as any entity loaded by Hibernate goes into one of these, we can use it without fear for the next one thousand requests. It can travel between components, and even between pages.

It is the session babysitter.

To be continued…


Hi Nathan, thanks for your effort with Databinder and these writings. Much appreciated!

My own Databinder-based project is unfortunately on hold due to too much paid daytime work. :-/ Making money is ok, but I wish I had time for this fun stuff as well. Maybe at xmas…

Thanks, I’m glad you’re enjoying the series. I’m hacking up a little app to display these at simultaneous to the 1.0 release. Maven’s site generator dosen’t render Textile, and I’m not about to rewrite this stuff in its crappy APT format. I’ve decided to move all of’s content into this new app eventually. But, yes, that free time is hard to come by!

Add a comment