-->
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: using Restriction and Projection classes
PostPosted: Fri Jul 13, 2007 8:32 am 
Newbie

Joined: Thu May 10, 2007 4:19 am
Posts: 5
Dear Sirs

The hql query below work fine:

String query = "select t from TextVersion as t where version = " +
"(select max(version) from TextVersion where headline_id = " +
headlineId + ") and headline_id=" + headlineId;

List textVersions = hibernateSupport.findByHQL(query);

the POJO class is TextVersion and I am able to retrieve objects from this class in List textVersions.

I need to replace this query by Criteria using Restriction and Projection classes:

DetachedCriteria criteria = DetachedCriteria.forClass(TextVersion.class);

criteria.setProjection(Projections.max("version"));
criteria.add(Restrictions.eq("headlineId", headlineId));

List textVersions = hibernateSupport.findByDetachedCriteria(criteria);

The problem is that I receive Integer objects represented the "version" field of the TextVersion that I need to retrieve in List textVersions.
This Integer values are the same that these ones of TextVersion objects that I need to retrieve, but I need of all TextVersion
objects not only filed 'version'.

What is necessary to set Criterion or Projection to get all the objects?

best regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 12:46 pm 
Newbie

Joined: Thu Dec 02, 2004 7:24 pm
Posts: 3
See the Subqueries class and the Detached Queries and Subqueries section of the manual.


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.