-->
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.  [ 5 posts ] 
Author Message
 Post subject: Best practise: save/update/delete with cascades from Parent?
PostPosted: Wed Dec 22, 2004 1:42 am 
Beginner
Beginner

Joined: Wed Dec 03, 2003 10:59 am
Posts: 47
Hibernate version: 2.15 or so

Hello,

I have a 'best practises' question.
I have a 'root' entity/table called User. Almost all other entities/tables are associated with this User entity via FKs.
e.g.
User <-- FK -- UserProfiles
User <-- FK -- UserMessages
User <-- FK -- UserDemographics
User <-- FK -- UserPreferences
...

I guess this would be the Parent/Child relationship from HIA and online docs.

I am wondering about the best way to deal with cascades and entity saveOrUpdate calls.

More precisely, I am wondering whether it is considered best practise to have a DAO layer and saveOrUpdate calls for each of the Child entities, or whether it is better to just make proper bidirectional associations between Parent/Child entities, along with cascade="all-delete-orphan" and then just always call saveOrUpdate(Parent), and rely on Hibernate doing all transitive persistence, dirty checking, and doing all inserts, updates and deletes based on the cascade setting?

I am just worried about always going through this Parent entity. It would make code simpler - there would be no need to DAO layer save/update/delete for individual Child entities, but are there any dangers associated (no pun intended, really) with this?
In my case the Parent has a few Bags (List collections) associated with it, and some of those collections can have several thousand entities in them.

I guess my primary worry is how efficient and reliable it is to let Hibernate iterate through such collections on every XA commit in order to find dirty objects in associated collections, as opposed to me manually calling save/update/delete on those entities when the application calls for that.

Thanks,
Otis


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 12:57 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 10:59 am
Posts: 47
Hello - just wondering if anyone has any advice about this.

If I have a DB where child tables point to the parent table via FK, are there any dangers in persisting (saving, updateing, and deleting) child entities by always going through the parent entity, as in:

ses.saveOrUpdate(parent);
or
ses.delete(parent);

Any dangers in that? (e.g. big object graph)

Thanks,
Otis


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It mostly depends on you business case. If you BC requires it, cascading save huge amounts of code. Do some perf tests before rejecting this feature.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 23, 2004 1:49 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 10:59 am
Posts: 47
Thanks Emmanuel.

But from the Hibernate point of view, there are no issues with this?

I mean, calling ses.saveOrUpdate(parent) and having Hibernate traverse and dirty-check 2-3 collections with 1000-10000 child entities each, and possibly update/inserte/delete a handful in each collection, each time this ses.saveOrUpdate(parent) is called.

Is anyone here doing this?
Is anyone from the Hibernate Team doing things this way in their own applications or in their clients' applications?

Thanks,
Otis


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 7:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There are no specific issue. But I must admit I usually does not cascade huge collections on dettached objects.

_________________
Emmanuel


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