-->
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: Don't dereference a collection with cascade="all-delete
PostPosted: Mon Apr 11, 2005 6:19 pm 
Newbie

Joined: Fri Apr 08, 2005 4:33 pm
Posts: 3
Hi,

In a one-to-many relationship, I am trying to dereference a child(interface) collection and then adding a new child collection to the parent(device).

When I tried this I got the HibernateException: Don't dereference a collection with cascade="all-delete-orphan"

I looked at the following explanation
http://www.hibernate.org/264.html

because of which I tried to clear the collection and saveorupdate the object. The problem is that though the parent reference is being removed the child object is not getting deleted so when I try to now add a new child I get the error shown below.

How am I supposed to get around this? Has automatic dereferencing worked for you?

Thanks,
Son

Full stack trace of any exception that occurs:
Hibernate: select interfaced_.if_name, interfaced_.device_ip as device2_1_ from interface_table interfaced_ where interfaced_.if_name=?
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.c.nm.tio.deviceLayer.InterfaceDB#fa2]
at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:549)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:251)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:214)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:416)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:153)
at org.hibernate.engine.Cascades.cascade(Cascades.java:721)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:860)
at org.hibernate.engine.Cascades.cascade(Cascades.java:739)
at org.hibernate.engine.Cascades.cascade(Cascades.java:817)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:112)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:59)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.c.nm.tio.deviceLayer.TestDB.update(TestDB.java:92)
at com.c.nm.tio.deviceLayer.DiceServer.main(DiceServer.java:281)

Hibernate version: 3.0

Name and version of the database you are using:
mysql 4.1

mapping [b]
In interface xml
<many-to-one name="device" class="com.c.nm.tio.deviceLayer.DeviceDB" column="device_ip" cascade="all" />


In device xml
<set name="interfaces" cascade="all-delete-orphan" inverse="true" lazy="true" table="interface_table">
<key column="device_ip" on-delete="cascade"/>
<one-to-many class="com.c.nm.tio.deviceLayer.InterfaceDB"/>
</set>

[b] session code [b]
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

DeviceDB dev = (DeviceDB)session.load(DeviceDB.class, ipAdd);
HashSet interfaces = new HashSet();
Iterator it = ifNames.iterator();
dev.getInterfaces().clear();
session.saveOrUpdate(dev);
System.out.println("interfaces cleared");
while(it.hasNext())
{
InterfaceDB i = new InterfaceDB((String)it.next());
dev.addInterface(i);


}
session.saveOrUpdate(dev);

tx.commit();
HibernateUtil.closeSession();

[b]The generated SQL (show_sql=true):

select interfaced_.if_name, interfaced_.device_ip as device2_1_ from interface_table interfaced_ where interfaced_.if_name=?
Debug level Hibernate log excerpt:


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.