i need to translate this SQL expression into Hibernate using Criteria
Code:
select id,field1,field2,count(*) from my_table
group by field1,field2 having count(*)>1;
here is my code so far.
Code:
final Session session = ......
ProjectionList projectionList = (ProjectionList)emptyProjection();
projectionList.add(Projections.property("id"),"id");
projectionList.add(Projections.groupProperty("codeI"));
projectionList.add(Projections.groupProperty("codeII"));
projectionList.add(Projections.sqlGroupProjection("count(*)","having count(*)>1",new String[]{},new Type[]{StandardBasicTypes.INTEGER}));
final Criteria criteria = session.createCriteria(MyClass.class).setProjection(projectionList).setResultTransformer(transformer(MyClass.class));
return new ArrayList<MyClass>(criteria.list());
my problem is
the criteria is generating this SQL.
Code:
group by
this_.FIELD1,
this_.FIELD2,
having
count(*)>1
as you can see the second group by is followed by a COMMA this_.FIELD2, and mySQL is throwing SyntaxError
UPDATE
here is my hibernate.cfg
Code:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
and we are using mysql 5.5.29 and HIBERNATE 4.2.3i hope somebody give a tip.
best regards..