[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-6627) SQLServer2008Dialect Bad Query

Dzmitry Liushtyk (JIRA) noreply at atlassian.com
Tue Apr 24 11:42:48 EDT 2012


    [ https://hibernate.onjira.com/browse/HHH-6627?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46396#comment-46396 ] 

Dzmitry Liushtyk edited comment on HHH-6627 at 4/24/12 10:41 AM:
-----------------------------------------------------------------

//

      was (Author: dzmitry):
    	protected static void replaceDistinctWithGroupBy(StringBuilder sql) {
		int distinctIndex = sql.indexOf(DISTINCT);
		int selectEndIndex = sql.indexOf(FROM);
		if (distinctIndex > 0 && distinctIndex < selectEndIndex) {
 			boolean aggregateFunctionAvailable = false;

			StringBuilder selectFieldsWithoutAlias = new StringBuilder(getSelectFieldsWithoutAliases(sql));
 			for (String functionName : AGGREGATE_FUNCTION_NAMES)
 			{                                                      
				Pattern p = Pattern.compile("\\s" + functionName + "\\s*\\(");
				Matcher matcher = p.matcher(selectFieldsWithoutAlias);
 				if(matcher.find())
 				{	
					aggregateFunctionAvailable = true;
 					break;
 				}
 			}

			if (!aggregateFunctionAvailable)
			{
				sql.delete(distinctIndex, distinctIndex + DISTINCT.length() + 1);
				sql.append(" group by").append(getSelectFieldsWithoutAliases(sql));
			}
		}
	}

  
> SQLServer2008Dialect Bad Query
> ------------------------------
>
>                 Key: HHH-6627
>                 URL: https://hibernate.onjira.com/browse/HHH-6627
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: query-sql
>    Affects Versions: 3.6.6, 3.6.7
>         Environment: JBoss 6.1.0 AS, SQL Server 2008
>            Reporter: Aleksandar Brankovic
>         Attachments: crit-prob.txt, SQLServer2005Dialect.patch
>
>
> Look at the file attached.
> Focus is on the next line:
> group by count(sale0_.id)
> It results in next error:
> Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list