-->
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.  [ 7 posts ] 
Author Message
 Post subject: Removing Child object from DB
PostPosted: Tue Jan 20, 2004 11:45 am 
Newbie

Joined: Wed Jan 14, 2004 11:29 am
Posts: 19
I've just ran into a problem (well for me anyway). I have a class called Department which has a collection of TradingAccounts(). This all persists OK in the database.

My problem occurs when I delete one of the items from this collection. Although my Collection of TradingAccounts no longer has a reference to it, it remains in the database!. I've read on the web (URL below) that this is the desired functionality for Hibernate, and I can see uses for this, however I don't want this functionality so it there a way to remove child objects from the database?

I also read that it is possible to use a cascade="all-delete-orphan" option to delete any child objects, however I treid this and it failed during the generate stage of my build process as this option is not specified in the DTD.

Any advice would be much appreciated,

Paul

URL: http://www.hibernate.org/hib_docs/refer ... child.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 11:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
all-delete-orphan is exactly for this. Are you using a recent version of hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 11:47 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use the latest Hibernate 2.1.1 and all-delete-orphan.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:32 am 
Newbie

Joined: Wed Jan 14, 2004 11:29 am
Posts: 19
I'm using Hibernate 2.1, and i've checked the DTD and it does allow the all-delete-orphan, but i'm using xDoclet to generate my .hbm.xml files. The build task has the following tag:

<replace dir="${gen-src.dir}">
<include name="**/*.hbm.xml"/>
<replacefilter token="readonly" value="inverse"/>
<replacefilter token="role" value="name"/>
<replacefilter token="hibernate-mapping.dtd" value="hibernate-mapping-2.0.dtd"/>
</replace>

This successfully renames the DTD to use the new one, however the build fails before this code is reached, so i'm assuming that the xDoclet task (xdoclet.modules.hibernate.HibernateDocletTask) for some reason isn't using the latest DTD?

Would an upgrade of xDoclet solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Use XDoclet 1.2 final (or CVS version) and remember to set the version attritbute to be "2.0" to get the correct mappings (and DTD reference).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 10:07 am 
Newbie

Joined: Wed Jan 14, 2004 11:29 am
Posts: 19
Yep this worked fine, although I did have to chane the following line in my build.xml file:

<replacefilter token="hibernate-mapping-1.1.dtd" value="hibernate-mapping-2.0.dtd"/>

And also change to the following parameters for the xDoclet tag on my class:

@hibernate.list cascade="all-delete-orphan" name="accounts" inverse="true"

This works great! :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just set version="2.0" in your <hibernate> ant task


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