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)
|