Hello All,
I have some problems getting hibernate to behave as I require. Hope you can help.
I have a simple class that manages a set of 'versioned' types (in this example BLOBS, but, relational objects must also be supported). In some cases we want to return all versions of the referenced data (an audit), but, in 99.9% of the cases (processing runtime) we only need the latest version of the underlying object. It is important to get only the latest version as in our domain there are many large/complex previous revisions.
We have a simple filter to allow us to extract only the latest revision. The problem is that many domain operations result in a new revision of the current object.
If the filter is not used everything works fine (but we pull back all previous revisions unnecessarily), if the filter is used, when we persist the 'VersionedComponent' we (obviously) loose all the previous revisions.
We in fact only want to assert the new version that was created from the current one (and not alter the originals).
We have tried marking the objects as 'mutable=false' (as they are immutable' but this still does not result in the required update. We cannot use inverse='true' and manage the persisted from the child end as some of the versioned components arenot in our domain model.
The details of our mapping is blow. I hope someone can help us solve this issue.
Thanks for your time!
Ori
PS: I have read the FAQ entry regarding the need to load an entire collection before altering elements, however, surely this is not the case for an immutable example like the one presented above?
Code:
<class name="com.domain.VersionedComponent"
table="versioned_components"
mutable="false"
>
....
<map name="componentVersions" sort="natural" cascade="save-update" table="component_versions mutable="false"">
<key column="component_id_fk"/>
<composite-map-key class="com.domain.Version">
<key-property name="revision" column="revision"/>
<key-property name="isHeadRevision" column="isHeadRevision"/>
</composite-map-key>
<element column="versioned_component">
<type name="com.dao.hibernate.types.ComponentBlobType"/>
</element>
<filter name="HeadRevisionOnlyFilter" condition="isHeadRevision='true'"/>
</map>
....
</class>
Hibernate v3.2
Postgres 8.0