|
Hello Chaps,
I am sure this is simple, but, cannot make it work. In my mapping file I have a 'version map', the key is the 'version; number (an integer) and the target is the object I want to persist:
<.. Parent Class Def ... <map name="componentVersions" sort="natural" cascade="save-update"> <key column="parent_id_fk"/> <composite-map-key class="test.domain.Version"> <key-property name="revision" column="revision"/> </composite-map-key> <one-to-many class="test.domain.VersionedInfo" /> </map> ... />
This works fine, and I can build up a set of my 'versioned' info objects, and I can retrieve all versioned objects.
Now I want to add a filter such that (if I active the filter in the session) hibernate will only return the latest version. I want to achieve this by telling hibernate to get only the latest result version [i.e: with the 'max(revision)'] e.g:
<map name="componentVersions" sort="natural" cascade="save-update"> <key column="parent_id_fk"/> <composite-map-key class="test.domain.Version"> <key-property name="revision" column="revision"/> </composite-map-key> <one-to-many class="test.domain.VersionedInfo" /> <filter name="LatestVersionFilter" condition="revision = (select max(revision) from versioned_info)" /> </map>
The above does not work and produces an error:
org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:77) >75> SQL Error: 0, SQLState: 42803 org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) >75> ERROR: aggregates not allowed in WHERE
I understand what the error means, and have tried various 'condition statements' but I always get errors. Has anyone or does anyone know hoe to achieve my desired functionality?
Thanks All!
I am using Hibernate v3.2 and Postgres v8.2.
|