File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes org.hibernate.LazyInitializationException: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.LazyInitializationException:" Watch "org.hibernate.LazyInitializationException:" New topic
Author

org.hibernate.LazyInitializationException:

premchand Singh
Greenhorn

Joined: Mar 12, 2012
Posts: 28
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.LazyInitializationException: