Inproper separator for nested unregistered sql function

Description

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

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

Activity

Show:
Brett Meyer
April 7, 2014, 5:43 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

Brett Meyer
July 8, 2014, 3:11 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Assignee

Unassigned

Reporter

Jürgen

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure