-->
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.  [ 1 post ] 
Author Message
 Post subject: execute select operation with Criteria
PostPosted: Wed Jul 11, 2007 8:29 am 
Newbie

Joined: Thu May 10, 2007 4:19 am
Posts: 5
Dear Sirs
I need to make ' select ' operation by hibernate Criteria IP with some conditions. In SQL my query is like this one:

HibernateSupport hibernateSupport = new HibernateSupport();

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 obeject from this class in List textVersions.

This hql query work. But by next code i receive ClassCastException:

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 this line:

criteria.setProjection(Projections.max("version"));

because I retrieve Integer objects 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'

best regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.