diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
index 04da5a447c..3bfa7a7695 100644
--- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
+++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
@@ -159,7 +159,7 @@ public class DB2Dialect extends Dialect {
registerFunction( "substring", new StandardSQLFunction( "substr", StandardBasicTypes.STRING ) );
registerFunction( "bit_length", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "length(?1)*8" ) );
- registerFunction( "trim", new AnsiTrimEmulationFunction() );
+ registerFunction( "trim", new SQLFunctionTemplate( StandardBasicTypes.STRING, "trim(?1 ?2 ?3 ?4)" ) );
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "", "||", "" ) );
diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/function/TrimFunction.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/function/TrimFunction.java
index a2fdc8ca49..489c23feaf 100644
--- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/function/TrimFunction.java
+++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/function/TrimFunction.java
@@ -37,6 +37,7 @@ import org.hibernate.jpa.criteria.expression.LiteralExpression;
* Models the ANSI SQL TRIM function.
*
* @author Steve Ebersole
+ * @author Brett Meyer
*/
public class TrimFunction
extends BasicFunctionExpression
@@ -118,11 +119,22 @@ public class TrimFunction
@Override
public String render(RenderingContext renderingContext) {
+ String renderedTrimChar;
+ if ( trimCharacter.getClass().isAssignableFrom(
+ LiteralExpression.class ) ) {
+ // If the character is a literal, treat it as one. A few dialects
+ // do not support parameters as trim() arguments.
+ renderedTrimChar = ( ( LiteralExpression )
+ trimCharacter ).getLiteral().toString();
+ } else {
+ renderedTrimChar = ( (Renderable) trimCharacter ).render(
+ renderingContext );
+ }
return new StringBuilder()
.append( "trim(" )
.append( trimspec.name() )
.append( ' ' )
- .append( ( (Renderable) trimCharacter ).render( renderingContext ) )
+ .append( renderedTrimChar )
.append( " from " )
.append( ( (Renderable) trimSource ).render( renderingContext ) )
.append( ')' )
diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java
index 666c189845..1dfddc7fa7 100644
--- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java
+++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java
@@ -92,8 +92,6 @@ public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
}
@Test
- @RequiresDialect( DB2Dialect.class )
- @FailureExpected( jiraKey = "HHH-6655" )
public void testTrim() {
final String expectedResult = "David R. Vincent";
EntityManager em = getOrCreateEntityManager();