-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Failed to lazily initialize a collection
PostPosted: Thu Sep 02, 2004 11:44 am 
Newbie

Joined: Fri Oct 03, 2003 8:44 am
Posts: 11
I'm getting a lazy initialization exception on a many to many relationship, however, I'm not marking any collections as lazy, so I can't understand why I'd get this!!


Hibernate version: 2.1.6

Database Schema
QHTACCTS
-------------
user_id (pk) - String

OS_MEMBERSHIP
--------------------
user_id (pk) - String
groupname (pk) - String

OS_GROUP
-------------
groupname (pk) - String


Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class name="supportutils.Group" table="OS_GROUP">
<id name="id" column="groupname" type="java.lang.String">
<generator class="assigned" />
</id>

<set name="accounts" table="OS_MEMBERSHIP" inverse="true">
<key column="groupname" />
<many-to-many class="supportutils.Account" column="user_id" />
</set>

</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class name="supportutils.Account" table="qhtaccts">

<id name="id" column="user_id" type="java.lang.String">
<generator class="assigned" />
</id>

<!-- <property name="loginName" column="user_id" type="java.lang.String" />-->

<property name="emailAddress" column="email" type="java.lang.String" />
<property name="password" column="pw" type="java.lang.String" />
<property name="firstName" column="first_name" type="java.lang.String" />
<property name="lastName" column="last_name" type="java.lang.String" />


<set name="groups" table="OS_MEMBERSHIP">
<key column="user_id" />
<many-to-many class="supportutils.Group" column="groupname" />
</set>


</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close(): I'm using Spring v.1.0.2, so...
public List findAll() {
return getHibernateTemplate().find("from Account a");
}

Spring configuration:
<!-- ========== Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingResources">
<list>
<value>supportutils/dao/hibernate/hbm/Account.hbm.xml</value>
<value>supportutils/dao/hibernate/hbm/Group.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<!-- ==================== DAO's -->
<bean id="accountDao" class="supportutils.dao.hibernate.AccountHibernateDao">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="groupDao" class="supportutils.dao.hibernate.GroupHibernateDao">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>


Full stack trace of any exception that occurs:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at net.sf.hibernate.collection.Set.endRead(Set.java:244)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:336)
at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3123)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at org.springframework.orm.hibernate.HibernateTemplate$17.doInHibernate(HibernateTemplate.java:331)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:170)
at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:328)
at supportutils.dao.hibernate.AccountHibernateDao.findAll(AccountHibernateDao.java:44)
at supportutils.dao.hibernate.AccountHibernateDaoTest.testFindAll(AccountHibernateDaoTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at net.sf.hibernate.collection.Set.endRead(Set.java:244)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
... 53 more
Caused by: net.sf.hibernate.LazyInitializationException: cannot access loading collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at net.sf.hibernate.collection.Set.endRead(Set.java:244)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
... 76 more


Name and version of the database you are using: MSSQL Server 2000

Debug level Hibernate log excerpt:
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.type.StringType - returning 'jira-users' as column: groupname__
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - found row of collection: [supportutils.Group.accounts#jira-users]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - reading row
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.type.StringType - returning 's.wiseman' as column: user_id__
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - loading [supportutils.Account#s.wiseman]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - attempting to resolve [supportutils.Account#s.wiseman]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - resolved object in session cache [supportutils.Account#s.wiseman]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - done processing result set (630 rows)
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - closing statement
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - total objects hydrated: 0
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - 1 collections were found in result set
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - initializing collection [supportutils.Account.groups#andreawaz]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - checking second-level cache
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - collection not cached
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.SQL - select groups0_.user_id as user_id__, groups0_.groupname as groupname__, group1_.groupname as groupname0_ from OS_MEMBERSHIP groups0_ inner join OS_GROUP group1_ on groups0_.groupname=group1_.groupname where groups0_.user_id=?
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - preparing statement
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.type.StringType - binding 'andreawaz' to parameter: 1
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - result set contains (possibly empty) collection: [supportutils.Account.groups#andreawaz]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - uninitialized collection: initializing
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - processing result set
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.type.StringType - returning 'jira-users' as column: groupname0_
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - result row: jira-users
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.type.StringType - returning 'andreawaz' as column: user_id__
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - found row of collection: [supportutils.Account.groups#andreawaz]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - reading row
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.type.StringType - returning 'jira-users' as column: groupname__
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - loading [supportutils.Group#jira-users]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - attempting to resolve [supportutils.Group#jira-users]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - resolved object in session cache [supportutils.Group#jira-users]
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - done processing result set (1 rows)
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.BatcherImpl - closing statement
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.loader.Loader - total objects hydrated: 0
02 Sep 2004 11:41:22 : [DEBUG] net.sf.hibernate.impl.SessionImpl - 1 collections were found in result set
02 Sep 2004 11:41:22 : [ERROR] net.sf.hibernate.LazyInitializationException - cannot access loading collection
net.sf.hibernate.LazyInitializationException: cannot access loading collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at net.sf.hibernate.collection.Set.endRead(Set.java:244)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at net.sf.hibernate.collection.Set.endRead(Set.java:244)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)
at java.util.HashMap.hash(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at java.util.HashSet.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at net.sf.hibernate.collection.Set.endRead(Set.java:244)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:336)
at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3123)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at org.springframework.orm.hibernate.HibernateTemplate$17.doInHibernate(HibernateTemplate.java:331)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:170)
at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:328)
at supportutils.dao.hibernate.AccountHibernateDao.findAll(AccountHibernateDao.java:44)
at supportutils.dao.hibernate.AccountHibernateDaoTest.testFindAll(AccountHibernateDaoTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
02 Sep 2004 11:41:22 : [ERROR] net.sf.hibernate.collection.PersistentCollection - Failed to lazily initialize a collection
net.sf.hibernate.LazyInitializationException: cannot access loading collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177)
at supportutils.AbstractDomainObject.hashCode(AbstractDomainObject.java:49)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
is your session closed when you're hitting the collection?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 12:51 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
I'm pretty sure that Collections default to lazy loading. If you don't want lazy loading you have to specify lazy="false"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 1:16 pm 
Newbie

Joined: Fri Oct 03, 2003 8:44 am
Posts: 11
duggant wrote:
I'm pretty sure that Collections default to lazy loading. If you don't want lazy loading you have to specify lazy="false"


They default to lazy="false". But I added that to both ends of the relationship just for fun, and still no good.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 1:18 pm 
Newbie

Joined: Fri Oct 03, 2003 8:44 am
Posts: 11
anthony wrote:
is your session closed when you're hitting the collection?


Yes, the session is already closed:

As an example:
public void testFindAll() {
assertEquals(665, accountDao.findAll().size());
}

...throws the exception in question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
from Account a join fetch a.groups

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 2:33 pm 
Newbie

Joined: Fri Oct 03, 2003 8:44 am
Posts: 11
Thanks for your help. I'm a moron - sorry for wasting your time:). Actually, it turns out that I have all my Hibernate persisted classes extending a class I call AbstractDomainObject, which uses Commons Lang to implement hashcode() as follows:

public int hashCode() {
// uses every property of the persistent class to calc. hashcode
return HashCodeBuilder.reflectionHashCode(this);
}

Once I got rid of this, and simply used the ID of the class to help generate the hashcode, my troubles disappeared.

Guess that goes to show me I shouldn't implement more than I really need to!!

Sorry for being dumb:D.

Might this be one for the FAQ's?

Jon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 3:35 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
search for equals & hashcode on the wiki

there are limitations using id to implementent these methods, you should better use business key

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.