[hibernate-issues] [Hibernate-JIRA] Issue Comment Edited: (HHH-3307) HQL query translation in real SQL ignores the dialect class

Robert Rodehorst (JIRA) noreply at atlassian.com
Fri Apr 6 15:36:48 EDT 2012


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

Robert Rodehorst edited comment on HHH-3307 at 4/6/12 2:35 PM:
---------------------------------------------------------------

Confirmed this issue by modifying HXTT's Microsoft Access dialect with the following {{transformSelectString}} function:

{code:title=com.hxtt.support.hibernate.HxttAccessDialect.java}

	public String transformSelectString(String select) {
		select = super.transformSelectString(select);
		
		// Find all joins
        	int count = 0;
        	int idx = 0;
        	String sub = " join ";
        	while((idx = select.indexOf(sub, idx)) != -1) {
        	    count++;
        	    idx += sub.length();
        	}
		
        	// Remove "outer" keywords and add nested parentheses
        	if (count > 0) {
        	    select = select.replaceAll(" left outer join ", ") left join ");
        	    select = select.replaceAll(" right outer join ", ") right join ");
        	    select = select.replaceAll(" inner join ", ") inner join ");
        	    select = select.replaceAll(" from ", " from " + StringHelper.repeat('(', count));
        	}
        
        	return select;
	}
{code} 

As mentioned in the original report, this works fine for loading Hibernate mappings. However, executing HQL queries with more than one join results in syntax errors, as the nested parentheses required for Access queries never get applied.

      was (Author: gooberking):
    Confirmed this issue by modifying HXTT's Microsoft Access dialect with the following transformSelectString function:

{code:title=com.hxtt.support.hibernate.HxttAccessDialect.java|borderStyle=solid}
	public String transformSelectString(String select) {
		select = super.transformSelectString(select);
		
		// Find all joins
        	int count = 0;
        	int idx = 0;
        	String sub = " join ";
        	while((idx = select.indexOf(sub, idx)) != -1) {
        	    count++;
        	    idx += sub.length();
        	}
		
        	// Remove "outer" keywords and add nested parentheses
        	if (count > 0) {
        	    select = select.replaceAll(" left outer join ", ") left join ");
        	    select = select.replaceAll(" right outer join ", ") right join ");
        	    select = select.replaceAll(" inner join ", ") inner join ");
        	    select = select.replaceAll(" from ", " from " + StringHelper.repeat('(', count));
        	}
        
        	return select;
	}
{code} 

As mentioned in the original report, this works fine for loading Hibernate mappings. However, executing HQL queries with more than one join results in syntax errors, as the nested parentheses required for Access queries never get applied.
  
> HQL query translation in real SQL ignores the dialect class
> -----------------------------------------------------------
>
>                 Key: HHH-3307
>                 URL: https://hibernate.onjira.com/browse/HHH-3307
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: query-hql
>    Affects Versions: 3.2.6
>         Environment: dialect file with special JoinFragment and a "transformSelectString" step
>            Reporter: Thomas Schilf
>
> We're using a special dialect class for a database. In the dialect is defined a own JoinFragment and a "transformSelectString" step.
> All workes fine by loading objects over a Criteria class.
> The generated SQL string is wrong by using named queries (HQL). The SQL string is in normal ANSI-SQL.
> The SqlGenerator and QueryTranslatorImpl classes from hibernate don't use the dialect class.

--
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