graeder wrote:
I'm basically trying to do the same thing and can't get it to work either. Also, I would like to save the count value as a property in my pojo, but it's not a mapped column, so I'm not sure how to do this.
There's an example using a Filter in the h3 docs under the Improving performance section. I use queries like the one below to test for the existence of objects. I think I got the original code from the 2.1.x docs.
I define a NamedQuery in my mapping file.
Code:
<query name="MyObject.existsQuery> <![CDATA[
select count(*) from MyObject myobj where myobj.m2o.id = :manyToOneId
]]>
</query>
And the Java Code looks like this.
Code:
Query q = session.getNamedQuery("MyObject.existsQuery");
q.setLong(InterventionSessionDVO.SESSION_ID, sessionId.longValue());
int count = ((Integer) q.iterate().next()).intValue();