[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4963) Inproper separator for nested unregistered sql function

Jürgen (JIRA) noreply at atlassian.com
Tue Mar 2 10:27:47 EST 2010


Inproper separator for nested unregistered sql function
-------------------------------------------------------

                 Key: HHH-4963
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4963
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.4.sp1
         Environment: Java version: 1.6.0_16,Sun Microsystems Inc.
Java VM: Java HotSpot(TM) 64-Bit Server VM 14.2-b01,Sun Microsystems Inc.
OS-System: Linux 2.6.25.14-69.fc8,amd64
Hibernate 3.2.4.sp1
JBosss-4.2.3.GA
DB2 v8 / JDBC Driver v4.7.85

            Reporter: Jürgen


HQL query clauses:
{{column1 LIKE CONCAT(CONCAT('%', REPLACE(:matchString, '%', '%%')), '%')}}
{{column1 LIKE '%' || REPLACE(:matchString, '%', '%%') || '%'}}

translate to:
{{t0_.column1 like '%'||REPLACE(?||'%'||'%%')||'%'}}

Investigation results:
* used dialect {{org.hibernate.dialect.DB2Dialect}} does not have "{{replace}}" as a registered function.
* "{{concat}}" is registered as a {{org.hibernate.dialect.function.VarArgsSQLFunction}} with "{{||}}" separator.
* invoked render method {{org.hibernate.hql.ast.SqlGenerator.beginFunctionTemplate(AST, AST)}} does put {{org.hibernate.hql.ast.SqlGenerator.FunctionArguments}} writer on stack for outer {{concat}} method
* 2. invocation of render method {{org.hibernate.hql.ast.SqlGenerator.beginFunctionTemplate(AST, AST)}} does *NOT* put a new FunctionsArgments writer on stack, *NOR* does it put the {{org.hibernate.hql.ast.SqlGenerator.DefaultWriter}} back on the stack --> outer {{concat}} method FunctionArguments writer captures replace method call output parts as its arguments: "replace(?", "'%'", "'%%')"

suggestion: in case of {{template == null}}, let {{org.hibernate.hql.ast.SqlGenerator.beginFunctionTemplate(AST, AST)}} put a new DefaultWriter on the stack, and {{org.hibernate.hql.ast.SqlGenerator.endFunctionTemplate(AST)}} remove it again.

workaround by subclassing dialect and registering "{{replace}}" function template, but still, other unregistered functions would be treated improperly.

eclipse vardump of {{functionArgments}} on {{org.hibernate.hql.ast.SqlGenerator.endFunctionTemplate(AST)}} for {{concat}}
{code}
functionArguments	org.hibernate.hql.ast.SqlGenerator$FunctionArguments  (id=322)	
	argInd	3	
	args	java.util.ArrayList<E>  (id=336)	
		elementData	java.lang.Object[5]  (id=342)	
			[0]	"'%'" (id=346)	
			[1]	"REPLACE(?" (id=347)	
			[2]	"'%'" (id=348)	
			[3]	"'%%')" (id=350)	
			[4]	null	
		modCount	4	
		size	4	
	this$0	org.hibernate.hql.ast.SqlGenerator  (id=279)	
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list