-->
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.  [ 3 posts ] 
Author Message
 Post subject: possible bug on CountProjection SQL generation
PostPosted: Thu Sep 12, 2013 8:52 am 
Newbie

Joined: Thu Sep 12, 2013 8:39 am
Posts: 2
hi all,

Ive searched the forums and JIRA and haven't found a report about this, so here it goes,

we have migrated a spring 2.5, Mysql 5.6 webapp from Hibernate 3.2.5GA to 3.6.1Final.

When we try to run a criteria query with countDistinct we get a Invalid SQL Syntax error:

Criteria criteria = session.createCriteria(example.class).setProjection(Projections.countDistinct("examplefield"));

The SQL generated is along the lines of:
select count(distinct, this_.examplefield) as y0_ from example this_

as you can see, there is a ',' char between the reserverd keyword distinct and the column.

Looking at the source (3.6.1 and upwards to latest), the sql is generated in the "render" method from class org.hibernate.dialect.function.StandardSQLFunction:

Code:
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
      StringBuffer buf = new StringBuffer();
      buf.append( name ).append( '(' );
      for ( int i = 0; i < arguments.size(); i++ ) {
         buf.append( arguments.get( i ) );
         if ( i < arguments.size() - 1 ) {
            buf.append( ", " );
         }
      }
      return buf.append( ')' ).toString();   
}


given that CountProjection class passes render an array with the keyword distinct and the columns, this results in the faulty SQL.

I would like to open a JIRA with this, but I dont know how :/ anyway, thanks for any input on this!


Top
 Profile  
 
 Post subject: Re: possible bug on CountProjection SQL generation
PostPosted: Fri Sep 13, 2013 6:07 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Thanks for the feedback,
you should be able to find all the details on how to open a JIRA and contirbute a patch on this page:
http://www.hibernate.org/issuetracker

Hope this has helped.

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: possible bug on CountProjection SQL generation
PostPosted: Fri Sep 13, 2013 6:57 am 
Newbie

Joined: Thu Sep 12, 2013 8:39 am
Posts: 2
will create a simple test case and add to JIRA during the weekend,

thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.