-->
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: Efficiency of huge bi-directional one-to-many associations
PostPosted: Thu Jul 07, 2005 5:56 pm 
Newbie

Joined: Mon Jun 20, 2005 2:51 pm
Posts: 13
Location: Brasil
I have two classes, a creator class and a "file" class. Every "file" that is created has a creator, so we have a simple one-to-many association.

Code:
<class name="Creator" table="creator" lazy="true">
   ...
        <set name="files"
             inverse="true"
             cascade="all-delete-orphan"
             lazy="true">
             <key>
                <column
                    name="creator_id"
                    not-null="true"/>
             </key>
           <one-to-many class="Files"/>
        </set>
</class>


and

Code:
<class name="Files" table="files" lazy="true">
   ...
        <many-to-one
            name="creator"
            class="Creator"
            foreign-key="fk_files_creator"
            cascade="none">
            <column
                name="creator_id"
                not-null="true"/>
        </many-to-one>
</class>


What I need is to delete the creator an subsequently all the "files" he has created. This can be quite a huge number (many thousands).

I read that if I want Hibernate to take charge of cascading deletes, I must declare this association as bidirectional, using scaffolding code. So everytime a file is created, I have to add it to the set of files of it´s creators class.

I am not concerned with the efficiency of the deletion, but I am concerned with the efficiency of the scaffolding code. The sets can become very large, and I never need the set only in case I want to delete the creator and everything he has created.

Is that the correct way to manage deletion of dependent objects?

Thanks in advance,

Axel W. Berle

_________________
Skype: 'axelberle'


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 7:41 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 2:43 pm
Posts: 29
Location: Silicon Valley
This could be a good candidate for hand-coded SQL. In whatever code deletes the creator, do a DELETE FROM FILES WHERE CREATOR_ID = :1. No muss, no fuss.


Top
 Profile  
 
 Post subject: Is it efficient or not?
PostPosted: Thu Jul 07, 2005 8:08 pm 
Newbie

Joined: Mon Jun 20, 2005 2:51 pm
Posts: 13
Location: Brasil
frusso wrote:
This could be a good candidate for hand-coded SQL. In whatever code deletes the creator, do a DELETE FROM FILES WHERE CREATOR_ID = :1. No muss, no fuss.


Hi,

I thought about that, but it would be nicer to do it the right way. If it was efficient, I would prefer it the Hibernate-way. My example is of course simplified: there are lots of other dependent tables, with their dependencies, foreign keys etc. I would have to write a lot of other delete statements first, complicating matters. In fact I have to delete a whole object graph.

So, is it efficient, or isn´t it?

_________________
Skype: 'axelberle'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 1:30 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 12:38 pm
Posts: 41
Location: Massachusetts, USA
I think the best advice is to try it, run some tests, collect some data, and determine for yourself if the performance is "good enough" for your userbase.

Chances are, it will be good enough, but you'll never know without trying, and no one else will be able to give you a definitive answer.


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.