-->
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: removing persistent/non-persistent items from collection
PostPosted: Mon Jun 20, 2005 11:16 pm 
Newbie

Joined: Fri Jun 03, 2005 4:08 am
Posts: 12
Hi,

I'm currently removing persistent objects (child objects already saved to DB) from collections like this (simplified code version):

Parent parent = (Parent) parentDAO.getObject(Parent.class, new Long(1));
Child child = (Child) childDAO.getObject(Child.class, new Long(request.getParameter("childId")));
parent.getChildren().remove(child);
parentDAO.saveObject(parent);

... which works.

My first question is, is there anyway to remove an already persistent object from a Set without pulling out an instance of it from the backend first to get a handle on it?

The problem im having is that the only info I get on which child to remove is the child's ID (which is typical) and I found that initializing a new object with that ID to try to leverage equals() and using Set.remove() wont work.

My second question is, for the same scenario, how do I remove a child that has not yet been saved yet to database (unsaved-value == null). Seems the only thing I can think of is to change the child's equals value to compare all fields and iterate one by one till i get the match, then use that object to remove itself from the collection...

Any input would be appreciated.

Thanks,
-Yves-


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.