Hello - I ahve asked this on the Hibernate forums but no one seems to have been able to provide an answer so I am trying here! Thanks chaps!
I have a collection in my model that contains a set of 'previous versions' of my root domain object. The previous versions are therefore 'immutable' and we will never want to update them, and only want to add past versions as they arise. 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:
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 withinverse="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