-->
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.  [ 4 posts ] 
Author Message
 Post subject: Best approach for model consistency
PostPosted: Wed Jun 06, 2007 12:44 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
We all the deal, relationship maintenance is the responsibility of the application.
If there is a relationship from Employee to ParkingSpace we have to do

employee.setParkingSpace(null);
and
parkingSpace.setEmployee(null);

before doing:

em.remove(employee);

My question is, is it not better to do this using the @PreRemove listener annotation? for example

@Entity
Employee {

@PreRemove
public void preRemove() {
if (parkingSpace != null) {
parkingSpace.setEmployee(null);
parkingSpace = null;
}
}
}

and

@Entity
ParkingSpace {

@PreRemove
public void preRemove() {
if (employee!= null) {
employee.setParkingSpace(null);
employee= null;
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 9:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's better to do it either manually or having a helper method in your object. The reason for that is consistency between managed and detached objects. Both should be handled the same way

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 12:27 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
emmanuel wrote:
It's better to do it either manually or having a helper method in your object. The reason for that is consistency between managed and detached objects. Both should be handled the same way

sorry, I am confused, you can't remove detached objects so why would consistency be an issue?
Also, when you say "having a helper method in your object" do you mean not to use the @PreRemove annotation at all, then?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Because a user used to the remove side effect, might expect that association reset is somewhat handled, which is wrong. But do as it pleases you :)

_________________
Emmanuel


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