-->
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.  [ 6 posts ] 
Author Message
 Post subject: collection is not associated with any session.
PostPosted: Thu Oct 25, 2007 3:21 am 
Newbie

Joined: Sat Oct 20, 2007 2:43 am
Posts: 11
Hi all,

I am trying to fetch one map but I am getting the following Exception:


org.hibernate.HibernateException: collection is not associated with any session
[java] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:449)
[java] at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:784)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
[java] at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
[java] at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
[java] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
[java] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[java] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
[java] at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
[java] at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
[java] at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
[java] at org.hibernate.collection.PersistentBag.size(PersistentBag.java:225)
[java] at Main.main(Main.java:56)
[java] Exception in thread "main" org.hibernate.HibernateException: collection is not associated with any session
[java] at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:449)
[java] at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:784)
[java] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
[java] at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
[java] at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
[java] at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
[java] at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[java] at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
[java] at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
[java] at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
[java] at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
[java] at org.hibernate.collection.PersistentBag.size(PersistentBag.java:225)



Please provide the solution as soon as possible

Thanks in advance!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 7:56 am 
Newbie

Joined: Sat Oct 20, 2007 2:43 am
Posts: 11
is there any one who know how to fix this bug? I am in the middle of my work Please help if any one knows it
Thanks in advance
Pawan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 9:44 am 
Newbie

Joined: Fri Aug 31, 2007 11:58 am
Posts: 19
It would be helpful if you can elaborate your problem,give some context.
Try to have a small test case which highlights the problem you are facing.

_________________
Note:Don't forget to rate,if useful.

Blog:http://elope.wordpress.com/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 9:53 am 
Newbie

Joined: Sat Oct 20, 2007 2:43 am
Posts: 11
I am having one map in my class. For the key column I am using property-ref to associate this foreign key with some other column of my class rather than primary key. the column other than primary key is not unique. now when I am trying to fetch this collection I am getting exception :



org.hibernate.HibernateException: collection is not associated with any session

I have searched on the google , and I have got that This is because we do not have objects with unique ids.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 4:11 pm 
Newbie

Joined: Thu Oct 25, 2007 1:06 pm
Posts: 2
Can you supply the session code from which this exception is being thrown?


Top
 Profile  
 
 Post subject: Re: collection is not associated with any session.
PostPosted: Thu Aug 12, 2010 10:52 am 
Newbie

Joined: Thu Aug 12, 2010 10:43 am
Posts: 1
I got this error when I use query.list(). I fix it by using query.iterate(); See codes below:
String query = "select D " + " FROM com.choicehotels.jpa.domain.HotDealEntity D " + " INNER JOIN D.hotel H "
+ " LEFT JOIN D.themes TH "
+ " WHERE D.categoryID in (:ids) "
+ " AND (D.startDate <= :date OR D.startDate IS NULL) " + " AND (D.endDate >= :date OR D.endDate IS NULL) "
+ " AND D.hotel.live = 1 "
+ " AND D.live = 1 AND D.language = :language";
String resultQuery = query;
Query q = session.createQuery(resultQuery);

q.setDate("date", new Date());
q.setParameter("language", language);
q.setParameterList("ids", ids);

//doesn't work here; if only one record back, no problem. if many records back, I get hibernate "collection is not associated with any session" exception
//q.setReadOnly(true).list();

q.setReadOnly(true);
for(Iterator i = q.iterate(); i.hasNext();) { //fix here
result.add(i.next());
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.