Hibernate in layered applications

Today I’ve made major changes to the model layer. Hibernate is soooo complicated… Maybe it’s a good thing for simple applications but in a layered one there are many issues you have to deal with.

My idea is now:

  • All collections are lazy to avoid sql queries
  • Everytime you need a collection you have to call the DAO to get it, this way you also ensure independency of the persistence mechanism used
  • When the DAO is called to get a collection it’s filtered to return only values not deleted (transactionTime.end is null)
  • findById should return a clone of the object returned by Hibernate because it’s cached, so next modifications in facades don’t affect persisted instances.

Hope this works when rerunning test cases tomorrow morning. Then I’ll commit the changes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s