-->
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.  [ 6 posts ] 
Author Message
 Post subject: many-to-one doesn't support all-delete-orphan|delete-orphan
PostPosted: Fri Aug 20, 2004 11:40 am 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
Hibernate version:
2.0.6

How come many-to-one only supports cascade

none|all|save-update|delete

Whereas

Set, Map etc etc support

none|all|save-update|delete|all-delete-orphan|delete-orphan

I am mapping a users details as a many-to-one class with
unique=true ... this works fine but orphans are being left
behind.

It would be cool if the all-delete-orphan & delete-orphan
were supported for this.

I have worked my way arround it now but it just strikes me
as something that would be cool to have consistent.

Rgds

Bryan

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 7:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
How would Hibernate figure out what object has been removed from a detached object?

Besides, cascade delete on a many-to-one is always semantically extremely suspect. (it would make sense for one-to-one, though).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 12:14 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
I am specifying the unique attribute so in reality it is a one-to-one
the problem with a one-to-one though is that the object that is
the primary key of the object which references the dependant
object is created using the generated method.

I have an object with several one to one attributes.

I would model them as custom types but for the fact that each contains
an array eg

SystemUser --- SystemUserDetails (one-to-one)
SystemUserDetails contains an array of Address objects.

Perhaps I am just not fully familliar with hibernate and
am doing this in an overly complicated manner.

My DAO code is unnecessarily complicated by this approach though
as I have to do the following to ensure there are no orphans left
behind.

snip=
public void updateDetails(SystemUser user, SystemUserDetails systemUserDetails) {
logger.debug("updateDetails called");
SystemUserDetails originalDetails = user.getSystemUserDetails();

if(originalDetails != null) {
systemUserDetails.setId(originalDetails.getId());
}

user.setSystemUserDetails(systemUserDetails);
..................
=snip


--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: i am going to try doing this with a component instead
PostPosted: Sat Aug 21, 2004 12:22 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
i am going to try doing this with a component instead.

I amn't sure if it has the same problem with orphans though.

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject: actually ....
PostPosted: Sat Aug 21, 2004 12:25 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
A quick look at the documentation suggests that a component
cannot contain an array . Is this correct ?

--b

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 3:45 pm 
Beginner
Beginner

Joined: Wed Mar 10, 2004 9:51 am
Posts: 42
Location: France
here for example is what has to be done in order to work with this
without creating loads of orphans.

public void updateMyDetails(SystemUserDetails systemUserDetails,
String username) {

//get the Session instance already bound to current thread and opened
Session session = SessionFactoryUtils.getSession(getSessionFactory(),
false);
try {
SystemUser systemUser;
List list = session
.find(
"From SystemUser as systemUser where systemUser.username = ?",
username, Hibernate.STRING);
if (!list.isEmpty()) {
systemUser = (SystemUser) list.get(0);

SystemUserDetails originalDetails = systemUser
.getSystemUserDetails();

if (originalDetails != null) {
systemUserDetails.setId(originalDetails.getId());
}
session.evict(originalDetails);
systemUser.setSystemUserDetails(systemUserDetails);

session.update(systemUser);

_________________
Pesimist: The glass is half empty
Optimist: The glass is half full
Engineer:The glass should be half that size


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