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: Problem with cascade delete
PostPosted: Mon Jun 25, 2007 9:20 am 
Newbie

Joined: Sat May 12, 2007 4:21 pm
Posts: 4
I have read the book, the documentation and FAQ. Still not able to figure this one out pls help.

I have two entity classes User and Patient.
...
@OneToMany(mappedBy = "user", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
@org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<Patient> patients = new HashSet<Patient>();
...

In the controller layer I have this delete method which uses an id from view layer to load a Patient for deletion.

public void delete()

Patient patient = patientDAO .findById(getDelete_id(), true);

//chase pointers and remove referrences from Users
List<User> listOfUsers = userDAO.chasePointersToPatient(patient);
logger.debug("size of set: "+ listOfUsers.size());//initalize collection

for(User u : listOfUsers) {
for(Patient p : u.getPatients()) {
if(p == patient) {
logger.debug("contains patient p: "+u.getPatients().contains(patient)+ "; size of set: "+ u.getPatients().size()); //contains patient p false; size of set 1
u.getPatients().remove(patient);
logger.debug("contains patient p: "+u.getPatients().contains(patient)+ "; size of set: "+ u.getPatients().size()); //contains patient p false; size of set 1
}
}
}
}

When I examine the u.getPatients() Set in debugger, i can see the exact same patient object, with same DB id, but some how u.getPatients.contains(patient) returns false? why?

p.s the code for userDAO.chasePointersToPatient is:

public List<User> chasePointersToPatient(Patient patient){
return (getSession()
.createQuery("from User u where :patient in elements(u.patients)")
.setParameter("patient", patient)
.list());
}


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.