Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.hibernate.LazyInitializationException:

 
premchand Singh
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have made one project , but with the following configuration in web.xml i am getting following exception

web.xml

<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Exception is :
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: EntitySpecification.attributeMap, no session or session was closed
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:375)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:368)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:111)
org.hibernate.collection.PersistentMap.values(PersistentMap.java:257)
com.unisys.holmes2.h2ng.softentity.business.impl.SoftEntitySpecificationImpl.getIdentityAttribute(SoftEntitySpecificationImpl.java:596)
com.unisys.holmes2.h2ng.softentity.business.impl.SoftEntitySpecificationImpl.loadEager(SoftEntitySpecificationImpl.java:754)
com.unisys.holmes2.h2ng.softentity.business.impl.SoftEntityRepositoryImpl.getEntitySpecification(SoftEntityRepositoryImpl.java:107)
com.unisys.holmes2.h2ng.softentity.business.impl.SoftEntityServiceImpl.getEntitySpecification(SoftEntityServiceImpl.java:220)
com.unisys.holmes2.tag.client.action.MaintainAssignmentsAction$3.compare(MaintainAssignmentsAction.java:676)
com.unisys.holmes2.tag.client.action.MaintainAssignmentsAction$3.compare(MaintainAssignmentsAction.java:671)
java.util.Arrays.mergeSort(Arrays.java:1270)
java.util.Arrays.mergeSort(Arrays.java:1282)
java.util.Arrays.mergeSort(Arrays.java:1281)
java.util.Arrays.mergeSort(Arrays.java:1281)
java.util.Arrays.mergeSort(Arrays.java:1281)
java.util.Arrays.sort(Arrays.java:1210)
java.util.Collections.sort(Collections.java:159)
com.unisys.holmes2.tag.client.action.MaintainAssignmentsAction.getTagsSorted(MaintainAssignmentsAction.java:671)
com.unisys.holmes2.tag.client.action.MaintainAssignmentsAction.getTagsWithEntities(MaintainAssignmentsAction.java:631)
com.unisys.holmes2.tag.client.action.MaintainAssignmentsAction.unisysExecute(MaintainAssignmentsAction.java:267)
com.unisys.holmes2.tag.client.action.UnisysAction.execute(UnisysAction.java:56)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Please suggest me some solution as i have been trying to get rid out of thid for last 2-3 days..
i have made the method @transactional even the same problem i am facing ..

thanks:
Premchand


 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LaziInitializationException is a Hibernate exception. Nothing to do with Spring.

Moving this to the ORM forum for you.

OH, and please use the CODE tags when posting code or configuration so we can read it.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally. Open Session In view is a major anti-pattern. Your Use case code should get all the data you need up front, and not wait for JSP rendering to go fetch more data. 1) It slows your application down tremendously because of all the database chatter back and forth, as opposed to getting all the data up front being one call to the database.

Now part of your question might relate to Spring in that you are using its OpenSessionInViewFilter class, but if you follow best practices and not use this anti-pattern, then it won't be a Spring question.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic