-->
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.  [ 2 posts ] 
Author Message
 Post subject: Refactoring a model to use only many-to-one associations
PostPosted: Thu Sep 10, 2009 3:16 am 
Newbie

Joined: Sun Aug 16, 2009 8:36 am
Posts: 7
Hello

I have a collection in my model that contains a set of 'previous versions' of domain object. The previous versions are therefore 'immutable' and we will never want to update them. Also the versioned domain object is fairly complex and causes heavy database access to retrieve.

When I have a new version of one of these objects I want to save it with the others without loading the entire set. The Advanced FAQ has some advice on this:

Quote:
Why does Hibernate always initialize a collection when I only want to add or remove an element?

Unfortunately the collections API defines method return values that may only be computed by hitting the database. There are three exceptions to this: Hibernate can add to a <bag>, <idbag> or <list> declared with inverse="true" without initializing the collection; the return value must always be true.

If you want to avoid extra database traffic (ie. in performance critical code), refactor your model to use only many-to-one associations. This is almost always possible. Then use queries in place of collection access.


I am new to all of this and am not 100% sure on how to refactor your model to use only many-to-one associations. Can anyone please give me an example of point me to a tutorial so that I can learn how this will resolves my issue?

Thanks

Ori


Top
 Profile  
 
 Post subject: Re: Refactoring a model to use only many-to-one associations
PostPosted: Fri Sep 11, 2009 5:18 am 
Newbie

Joined: Thu Sep 10, 2009 9:31 am
Posts: 1
Hi Ori,

You should be able to find everything you need in the FAQ

Kind regards,

BillH


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