-->
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: Java Hibernate sqlGroupProjection mysql Syntax error
PostPosted: Fri Oct 04, 2013 5:45 pm 
Newbie

Joined: Sun Nov 13, 2011 4:35 pm
Posts: 6
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.3

i hope somebody give a tip.

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.