Hello All,
I have project in which we have used spring-hibernate with tomcat, In our project we have several one->Many relationships. So we are having set for all the child record in parent class.
For Child Sets We have done lazy="true" in hbm.xml file.so the objects does not load if not required.
and to load the lazy objects in jsp we have used open session in view filter.
In our application we have multiple session factories as there are multiple replica databases for the different group of users.
on login user selects the group and login into the application, We store this group name into session to identify the user's session factory.
so according to the group we change hibernateTemplate and sessionfactory.
We are storing the session factories into the map<key,sessionfactory> for all of our user group. We have created custom class which extends OpenSessionInViewFilter and overridden the method lookupSessionFactory(HttpServletRequest request). in this method we get the group from request's session,and find the sessionfactory from the map and return that sessionfactory.
same way in dao classes we provide hibernateTemplate as per the group.
We find the following exception while rendering the view.
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.map.cms.bus.data.OverlayGroup.overlayGroupToUs erGroups, no session or session was closed org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationException(AbstractPersi stentCollection.java:380) org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:372) org.hibernate.collection.AbstractPersistentCollect ion.initialize(AbstractPersistentCollection.java:3 65) org.hibernate.collection.AbstractPersistentCollect ion.read(AbstractPersistentCollection.java:108)
While debugging we found that while rendering the view the lazy objects are having session null. some how the filter opensessioninviewfilter class can not assign the hibernate session to lazy objects.
Thanks in advance for your help,
|