views:

51

answers:

2
  1. How do you handle Hibernate Session in Business Layer?
  2. Do you tie your Business Layer to native Hibernate API? (e.g. use session.load() in UserService.java)
  3. Any design pattern for Business Layer? Best Practices?

I'm using hibernate-core 3.5.3-Final, Spring MVC 3.0.3.RELEASE.

+2  A: 

I do NOT handle the Session in the Business layer so I don't tie it to the native Hibernate API. I handle the Session in the DAO layer (using template-less DAOs). I use the business layer for transaction control and demarcation.

Pascal Thivent
+1  A: 

It is not desirable to propagate Hibernate's Session into the business layer. Hibernate Session should be encapsulated in your Data access layer (DAOs). The business layer should be implemented only in terms of the domain objects (loaded by hibernate) without any knowledge of hibernate. If you make your business layer transactional (using Spring transactions), then your business layer can access all the lazily loaded fields in your hibernated domain objects without any problem (as Hibernate's session will be open for the duration of Spring transaction).

Sasi