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