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
|