diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java index b595c7e160..4498fbf4b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java @@ -778,11 +778,8 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement true ); - this.criteriaLiteralHandlingMode = strategySelector.resolveStrategy( - LiteralHandlingMode.class, - configurationSettings.get( CRITERIA_LITERAL_HANDLING_MODE ), - LiteralHandlingMode.AUTO, - (clazz) -> LiteralHandlingMode.AUTO + this.criteriaLiteralHandlingMode = LiteralHandlingMode.interpret( + configurationSettings.get( CRITERIA_LITERAL_HANDLING_MODE ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/LiteralHandlingMode.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/LiteralHandlingMode.java index 8b384ce017..bc640ce491 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/LiteralHandlingMode.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/LiteralHandlingMode.java @@ -6,6 +6,8 @@ */ package org.hibernate.query.criteria; +import org.hibernate.HibernateException; + /** * This enum defines how literals are handled by JPA Criteria. * @@ -25,5 +27,33 @@ public enum LiteralHandlingMode { AUTO, BIND, - INLINE + INLINE; + + /** + * Interpret the configured literalHandlingMode value. + * Valid values are either a {@link LiteralHandlingMode} object or its String representation. + * For string values, the matching is case insensitive, so you can use either {@code AUTO} or {@code auto}. + * + * @param literalHandlingMode configured {@link LiteralHandlingMode} representation + * @return associated {@link LiteralHandlingMode} object + */ + public static LiteralHandlingMode interpret(Object literalHandlingMode) { + if ( literalHandlingMode == null ) { + return AUTO; + } + else if ( literalHandlingMode instanceof LiteralHandlingMode ) { + return (LiteralHandlingMode) literalHandlingMode; + } + else if ( literalHandlingMode instanceof String ) { + for ( LiteralHandlingMode value : values() ) { + if ( value.name().equalsIgnoreCase( (String) literalHandlingMode ) ) { + return value; + } + } + } + throw new HibernateException( + "Unrecognized literal_handling_mode value : " + literalHandlingMode + + ". Supported values include 'auto', 'inline', and 'bind'." + ); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/CriteriaLiteralHandlingModeInlineShortNameLowercaseTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/CriteriaLiteralHandlingModeInlineShortNameLowercaseTest.java new file mode 100644 index 0000000000..db2ff88ba6 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/CriteriaLiteralHandlingModeInlineShortNameLowercaseTest.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.jpa.test.criteria.literal; + +import java.util.Map; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.H2Dialect; + +import org.hibernate.testing.RequiresDialect; + +/** + * @author Vlad Mihalcea + */ +@RequiresDialect(H2Dialect.class) +public class CriteriaLiteralHandlingModeInlineShortNameLowercaseTest extends AbstractCriteriaLiteralHandlingModeTest { + + @Override + protected Map getConfig() { + Map config = super.getConfig(); + config.put( + AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE, + "inline" + ); + return config; + } + + protected String expectedSQL() { + return "select 'abc' as col_0_0_, abstractcr0_.name as col_1_0_ from Book abstractcr0_ where abstractcr0_.id=1 and abstractcr0_.name='Vlad''s High-Performance Java Persistence'"; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/CriteriaLiteralHandlingModeInlineShortNameUppercaseTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/CriteriaLiteralHandlingModeInlineShortNameUppercaseTest.java new file mode 100644 index 0000000000..17def5a97d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/literal/CriteriaLiteralHandlingModeInlineShortNameUppercaseTest.java @@ -0,0 +1,36 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.jpa.test.criteria.literal; + +import java.util.Map; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.query.criteria.LiteralHandlingMode; + +import org.hibernate.testing.RequiresDialect; + +/** + * @author Vlad Mihalcea + */ +@RequiresDialect(H2Dialect.class) +public class CriteriaLiteralHandlingModeInlineShortNameUppercaseTest extends AbstractCriteriaLiteralHandlingModeTest { + + @Override + protected Map getConfig() { + Map config = super.getConfig(); + config.put( + AvailableSettings.CRITERIA_LITERAL_HANDLING_MODE, + "INLINE" + ); + return config; + } + + protected String expectedSQL() { + return "select 'abc' as col_0_0_, abstractcr0_.name as col_1_0_ from Book abstractcr0_ where abstractcr0_.id=1 and abstractcr0_.name='Vlad''s High-Performance Java Persistence'"; + } +}