-->
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: collection is not associated with any session
PostPosted: Tue Jul 17, 2012 10:33 pm 
Newbie

Joined: Tue Jul 17, 2012 10:19 pm
Posts: 1
The POJO Class is like this.

public class User
{
private String mId = null;
private final Collection<RescalMem> mRescalMemSet;
}

and hibernate Mapping files is:

<class name="com.User" table="USER" mutable="true" >
<id name = "mId" access="field" column="USR_ID" type="java.lang.String" length="36">
<generator class="assigned"/>
</id>
<set batch-size="250" name="mRescalMemSet" access="field" table="RESCAL_MEM" order-by="INDEXNUM asc" lazy="true" fetch="select" cascade="all-delete-orphan" inverse="true">
<key column="USR_ID"/>
<one-to-many class="com.RescalMem"/>
</set>
</class>

now when the first time i get the data from the database, it's fine.
but when there is something in the data "RescalMem" i want to set the collection as leer, and save the User with a leer RescalMem.

Code like:
session.clear();
User user = session.get(User.class, mUser.getId());
user.getRescalMemSet().clear();
try
{
session.merge(user);
session.commit();
}
catch(Exception e)
{

}

Error occurs:
org.hibernate.HibernateException: collection is not associated with any session
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:471)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:867)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:264)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3072)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:842)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:835)


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.