-->
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: how to delete child
PostPosted: Mon Sep 15, 2003 5:12 am 
Newbie

Joined: Thu Aug 28, 2003 11:19 pm
Posts: 17
i have a question

parent class: tracker.class,it contain tow child class
child class :trackeritem.class
child calss:Trackeremail.class

i want delete the all the child trackeritem of the parent tracker,i set the cascade=all

tracker tk=new tracker();
session.delete(tk);

i can't use above the way to delete ,because session.delete(tk) will delete not only all the trackeritems,but also all the trackeremails.

now i only want delete all the trackeritems.

if my code like this

Code:
for(Iterator ite=tk.getTrackeritems().iterator();ite.hasNext();){
tki=(Trackeritem)ite.next();
tk.getTrackeritems().remove(tki);
session.delete(tki);
}


will throw a error ConcurrentModificationException, how do i resolve it

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2003 9:48 pm 
Newbie

Joined: Thu Aug 28, 2003 11:19 pm
Posts: 17
why no one answer my question?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2003 10:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Maybe because this is standard java functionality, and has really nothing what-so-ever to do with Hibernate.

ConcurrentModificationException is saying that you are attempting to access an iterator backed by a fail-fast collection after that collection has been structurally altered through a means other than the iterator.

The correct answer would be something like:
Code:
for(Iterator itr=tk.getTrackeritems().iterator();itr.hasNext();)
{
    session.delete(itr.next());
    itr.remove();
}


Check out http://java.sun.com/j2se/1.3/docs/api/java/util/ConcurrentModificationException.html


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.