-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception when trying to remove an object with collections
PostPosted: Tue Jan 08, 2008 1:37 pm 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
I'm having this exception when trying to remove a persistent object that contains one many-to-one relation and one set many-to-many relation.
I've searched for the error and I've found some people had problem with collections and cascade constraints, so I've put them to null, but the problem persists.
I'm using Spring and HibernateDAOs.

I think I'm doing everything OK to remove the object. First I search por the persisted instance based on the identifier with:

Theme theme = getPersistenceService().findTheme(themeID);

and then I try to remove it with:

getThemeDAO().delete(theme);

The findTheme method uses a find by example query type.

I've omitted some mapping information that I think it's not relevant.
Hope anyone help me with this.

Hibernate version: 3.0

Mapping documents:

<class name="Theme"
table="theme">
<comment>Available themes to be downloaded</comment>
<id name="id" type="java.lang.Long">
<column name="ID">
<comment>Surrogated Key</comment>
</column>
<generator class="sequence">
<param name="sequence">THEME_SEQ</param>
</generator>
</id>
<property name="theme_id" type="java.lang.String" unique="true" unique-key="THEME_ID">
<column name="THEME_ID">
<comment>Theme identifier</comment>
</column>
</property>
<many-to-one name="provider"
class="Provider" fetch="select" foreign-key="THM_VID_FK" cascade="none">
<column name="VENDOR_ID">
<comment>Vendor info for media definition</comment>
</column>
</many-to-one>
<set name="mediaObjects" table="theme_composition" cascade="none">
<key column="MEDIA_ID" />
<many-to-many column="MEDIA_OBJECT_ID"
class="MediaObject" />
</set>
</class>

<class name="Provider" table="vendor">
<id name="id" type="java.lang.Long">
<column name="ID">
<comment>Surrogated Key</comment>
</column>
<generator class="sequence">
<param name="sequence">VENDOR_SEQ</param>
</generator>
</id>
</class>
Code between sessionFactory.openSession() and session.close():

Theme theme = getPersistenceService().findTheme(themeID);
getThemeDAO().delete(theme);


Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException: Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:659)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:791)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:787)
at
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
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 sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javax.management.modelmbean.RequiredModelMBean.invokeMethod(Unknown Source)
at javax.management.modelmbean.RequiredModelMBean.invoke(Unknown Source)
at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(Unknown Source)
at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.access$100(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source)
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 sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:43)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:101)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:52)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:797)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
Name and version of the database you are using:
Oracle 9


Last edited by dancantong on Mon Mar 03, 2008 3:45 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 4:26 am 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
Please, any idea with this?

It seems the problem comes when I first query the object to remove by its ID and then I delete it. I use spring getHibernateTemplate().delete() method for it.
Is there any other way to delete the object without querying for it first? I mean, setting manually its id or anything else?


Top
 Profile  
 
 Post subject: Re: Exception when trying to remove an object with collections
PostPosted: Tue Sep 29, 2009 5:17 pm 
Newbie

Joined: Tue Sep 29, 2009 5:15 pm
Posts: 1
Hi dancantong,

Did you get the solution for your issue. I am trying to do the same thing, ending up with the exception.


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