1. I can't find "since Hibernate 3.0.1 OpenSessionInView is built-in without having to use Spring..." . What do I need to do special to use this built-in feature?
2. In our Struts->EJB->Hibernate application, we have mutltiple Hibernate session open/close calls made before the requested page is returned to the user. If I understand this correctly using 'OpenSessionInView' pattern the hibernate session would be opened & closed only once. Can anyone comment on performance, memory consumption, server load, connection limitations, connection pool sizes, etc. This would be used to justify this big code modification which would probably involve stripping out all those getCurrentSession() and closeSession() calls in the Data access layer (Dal) classes.
In a Struts->EJB->Hibernate application with the following sample Object hierarchy:
Client
|-ClientGUID
|-FirstName
|-LastName
+-Roles (Map) (lazy=true)
|--RoleCode
|--Role
|
+-AddressRoles (Map) (lazy=true)
|--AddressRoleCode
|--Address
In a typical HTTP request:
* In the business layer with ClientGUID obtained from the Struts ActionForm we fetch the Client object in the DAO (Hibernate session open & close)
* In the business layer we realize we need more of the Client details. And, since accessing them on the retrieved Client object instance gives LazyInitializationException, we use the ClientGUID to lookup the Roles & AddressRoles using the data access layer DAOs(Hibernate session open & close in both cases)
But, with the OpenSessionInView pattern it sounds like for the entire Request-Response cycle there will be only one Hibernate session open & close. On the face of it it seems like this would be a better performer since opening & closing database connections/sessions is an expensive operation I would imagine.
Any coments, suggestions?
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: