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: Hibernate Filter with Condition based on Aggregate
PostPosted: Sun Aug 16, 2009 9:04 am 
Newbie

Joined: Sun Aug 16, 2009 8:36 am
Posts: 7
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.


Top
 Profile  
 
 Post subject: Re: Hibernate Filter with Condition based on Aggregate
PostPosted: Tue Aug 18, 2009 3:07 am 
Newbie

Joined: Sun Aug 16, 2009 8:36 am
Posts: 7
Not many replies regarding my issue!

In that case if anyone could confirm that it is not possible then I can begin to search for a different solution. Can I assume it is not possible to use an subselect projected aggregated as a condition to a filter?


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.