Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HHH-6655 trim function on DB2 is broken

  • Loading branch information...
commit 11dcd9ab46d9474a54d79c5677804bceec2361e9 1 parent 58fa4c2
@brmeyer brmeyer authored
View
2  hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java
@@ -159,7 +159,7 @@ public DB2Dialect() {
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, "", "||", "" ) );
View
14 hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/expression/function/TrimFunction.java
@@ -37,6 +37,7 @@
* Models the ANSI SQL <tt>TRIM</tt> function.
*
* @author Steve Ebersole
+ * @author Brett Meyer
*/
public class TrimFunction
extends BasicFunctionExpression<String>
@@ -118,11 +119,22 @@ public void registerParameters(ParameterRegistry registry) {
@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<Character> )
+ 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( ')' )
View
2  hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/CriteriaCompilingTest.java
@@ -92,8 +92,6 @@
}
@Test
- @RequiresDialect( DB2Dialect.class )
- @FailureExpected( jiraKey = "HHH-6655" )
public void testTrim() {
final String expectedResult = "David R. Vincent";
EntityManager em = getOrCreateEntityManager();
Please sign in to comment.
Something went wrong with that request. Please try again.