-->
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.  [ 1 post ] 
Author Message
 Post subject: cannot access loading collection help
PostPosted: Sat Mar 05, 2005 4:53 pm 
Newbie

Joined: Sat Mar 05, 2005 4:38 pm
Posts: 4
Hey Hibernators!

I'm a new guy trying to get into hibernate with spring, and I need a little help with my one to many relationship.

A Project has Many Project Logs.. But as you'll see below, the collection is giving me problems.

:Project.hbm.xml contains:
<set name="projectLogs" inverse="true">
<key column="project_id"/>
<one-to-many class="org.appfuse.model.ProjectLog"/>
</set>

:ProjectLog.hbm.xml contains:
<many-to-one name="project" column="project_id" class="org.appfuse.model.Project"/>


:Project.java contains:

private Set projectLogs = new HashSet();
public Set getProjectLogs() {
return projectLogs;
}

public void addProjectLogs(ProjectLog projectLog) {
getProjectLogs().add(projectLog);
}

public void setProjectLogs(Set projectLogs) {
this.projectLogs = projectLogs;
}

:ProjectDAO.java contains:

public List getProjects() {
return getHibernateTemplate().find("from Project");
}

Full stack trace of any exception that occurs:

[junit] Testcase: testGetProjects(org.appfuse.dao.ProjectDAOTest): Caused an ERROR
[junit] cannot access loading collection
[junit] net.sf.hibernate.LazyInitializationException: cannot access loading collection
[junit] at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:191)
[junit] at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
[junit] at net.sf.hibernate.collection.Set.hashCode(Set.java:383)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:353)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:327)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:194)
[junit] at org.appfuse.model.BaseObject.hashCode(BaseObject.java:28)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:392)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:353)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:327)
[junit] at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:194)
[junit] at org.appfuse.model.BaseObject.hashCode(BaseObject.java:28)
[junit] at java.util.HashMap.hash(HashMap.java:261)
[junit] at java.util.HashMap.put(HashMap.java:379)
[junit] at java.util.HashSet.add(HashSet.java:192)
[junit] at java.util.AbstractCollection.addAll(AbstractCollection.java:319)
[junit] at net.sf.hibernate.collection.Set.endRead(Set.java:244)
[junit] at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3082)
[junit] at net.sf.hibernate.impl.SessionImpl.endLoadingCollections(SessionImpl.java:3069)
[junit] at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:320)
[junit] at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
[junit] at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
[junit] at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
[junit] at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
[junit] at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
[junit] at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
[junit] at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3268)
[junit] at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:336)
[junit] at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3123)
[junit] at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)
[junit] at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
[junit] at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
[junit] at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
[junit] at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
[junit] at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
[junit] at org.springframework.orm.hibernate.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:501)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:243)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:263)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:498)
[junit] at org.appfuse.dao.hibernate.ProjectDAOHibernate.getProjects(ProjectDAOHibernate.java:20)
[junit] at org.appfuse.dao.ProjectDAOTest.testGetProjects(ProjectDAOTest.java:66)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

:Conclusions:

As you can see, the problem starts when the test trys to call ProjectDAOHibernate.getProjects(), of which I included above. Really nothing to it.

The interesting thing is, I can call getProjects just fine up until the point that I add a single ProjectLog. As soon as I add a project log (which works), calling getProjects then yields this error.

Please Help!! Thanks!

-Gregg


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

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.