diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/NamedQueryBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/NamedQueryBinder.java index 23adf34316..9c5d4f5151 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/NamedQueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/NamedQueryBinder.java @@ -45,10 +45,14 @@ public class NamedQueryBinder { for ( Object content : namedQueryBinding.getContent() ) { if ( String.class.isInstance( content ) ) { - query = (String) content; + String trimmed = ((String)content).trim(); + if (!"".equals(trimmed)) { + query = trimmed; + } } else { - final JaxbHbmQueryParamType paramTypeBinding = (JaxbHbmQueryParamType) content; + final JaxbHbmQueryParamType paramTypeBinding = + (JaxbHbmQueryParamType)((JAXBElement)content).getValue(); if ( parameterTypeMap == null ) { parameterTypeMap = new HashMap(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java new file mode 100644 index 0000000000..42553cc591 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/hbm/query/NamedQueryTest.java @@ -0,0 +1,47 @@ +package org.hibernate.test.hbm.query; + +import java.io.StringReader; + +import org.hibernate.cfg.Configuration; +import org.hibernate.engine.jdbc.ReaderInputStream; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.junit.Test; + +/** + * @author Koen Aers + */ +@TestForIssue( jiraKey = "HHH-10223" ) +public class NamedQueryTest extends BaseUnitTestCase { + + private static String NAMED_QUERY_HBM_XML = + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " from NamedQueryTest$Bar where foo like :foo "+ + " "+ + " "+ + " "; + + @Test + public void testQuery() { + Configuration cfg = new Configuration(); + cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); + cfg.addInputStream(new ReaderInputStream(new StringReader(NAMED_QUERY_HBM_XML))); + cfg.buildSessionFactory(); + } + + public class Bar { + private Integer id; + private String foo; + public Integer getId() { return id; } + public void setId(Integer id) { this.id = id; } + public String getFoo() { return foo; } + public void setFoo(String foo) { this.foo = foo; } + } + +}