我需要把它翻译SQL expression
成Hibernate
使用Criteria
select id,field1,field2,count(*) from my_table
group by field1,field2 having count(*)>1;
到目前为止,这是我的代码。
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());
我的问题是
标准正在生成此 SQL。
group by
this_.FIELD1,
this_.FIELD2,
having
count(*)>1
如您所见,第二组 by 后面是 aCOMMA
this_.FIELD2,
并且 mySQL 正在抛出SyntaxError
更新
这是我的hibernate.cfg
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
我们正在使用mysql 5.5.29
和HIBERNATE 4.2.3
我希望有人给小费。
此致..