I have a complex problem on my hands.
I am trying to do a select of 4 fields out of 16 in my object with criteria. It wasn't working until I used
setResultTransformer(Transformers.aliasToBean(Clazz.class)).
I am trying to do the exact same thing but selecting fields of a composite-id : id.field1, id.field2, id.field3 and field4.
Here is the criteria code:
Code:
criteria = session.createCriteria(Clazz.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("id.field1"), "id.field1");
projList.add(Projections.property("id.field2"), "id.field2");
projList.add(Projections.property("id.field3"), "id.field3");
projList.add(Projections.property("field4"), "field4");
criteria.setProjection(projList);
criteria.add(Restrictions.eq("id.field1", field1));
criteria.add(Restrictions.eq("id.field2", field2));Clazz.class));
It generates this SQL:
Code:
select this_.FIELD1 as y0_, this_.FIELD2 as y1_, this_.FIELD3 as y2_, this_.FIELD4 as y3_ from Table1 this_ where y1_=? and y0_=?
Fields 1, 2 and 3 are in the class ClazzId and field 4 is in Clazz. I mapped a composite-id with these 3 fields.
I get an error of this type:
Code:
junit.framework.AssertionFailedError: error in getFields: org.hibernate.exception.SQLGrammarException: could not execute query
Can someone tell me what I did wrong and what can I do to resolve it?