-->
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: Updating a new object that has an existing id
PostPosted: Thu Sep 30, 2004 7:02 pm 
Newbie

Joined: Thu Sep 30, 2004 6:07 pm
Posts: 6
Location: Amsterdam
I really enjoyed reading a few chapters from HIA. Cool book! Thanks!

I'm working on a project that plans to use Hibernate to update objects in a local database that were sent via XML from a remote database.

An issue that arises here is wether Hibernate supports the possiblity of updating an object that was newly constructed but has an existing id in the database (instead of updating an object that was loaded through a session).

I tested this but I can't get the cascading right: Hibernate won't do an orphan delete of the children in the object graph.

Here's what I do: I contruct an object graph from XML. Ids of all objects are existing in the database, or are of unsaved-value. Then I open a session and call saveOrUpdate().

What happens is that the root object is persisted correctly, but the children are not deleted by the cascade rule all-delete-orphan. So updating an object with only 2 children while there are 3 in the database does not delete the third.

Does Hibernate support this case? As I understood from the book (HIA) this is what the transparancy of persistence is about, and newly constructed objects can be brought into the session again and be persisted.

Any hints here? Thanks!!
Paul.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 7:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Not really, it is intended that you use a detached instance for this.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 7:14 pm 
Newbie

Joined: Thu Sep 30, 2004 6:07 pm
Posts: 6
Location: Amsterdam
[Sorry, this got submitted as a new topic, I pressed the wrong button (doh!)]

Ok. Thanks!

I don't like to ask RTFM questions but how do I make a newly constructed instance detached? Or do you mean that I should get() an instance, then detach and copy bean properties? Hope not.

Thanks.
P.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 5:17 am 
Newbie

Joined: Thu Sep 30, 2004 6:07 pm
Posts: 6
Location: Amsterdam
Put diffently and perhaps more clearly: what is the difference, from Hibernate's point of view, between a newly constructed instance (that never was under Hibernate management) and a detached instance (one that was once under Hibernate management, but is not now so)?

HIA says that Hibernate does not keep references to detached instances, so that means Hibernate can't see the difference described. Right?

Thanks again,
P.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 8:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is no difference, if the objects are identical (all properties, associations identical)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 8:29 am 
Newbie

Joined: Thu Sep 30, 2004 6:07 pm
Posts: 6
Location: Amsterdam
If I understand it correctly, since there is no difference between new and detach objects, Gavin's advice that
Quote:
(...) it is intended that you use a detached instance for this.

is good advice, but I'm already doing that, because the instances in the problem described above are new, and thus also detached.

Is the conclusion right that the describes use case is ok in principle, and that something simple must be wrong, like mapping or something else?

Then I'll know I'm on the right track, and will do some more research into the problem.

Thanks.

Paul.


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.