Skip to content

Commit 71765d7

Browse files
committed
HHH-10223: Element 'query-param' in *.hbm.xml files causes ClassCastException
1 parent 0638a54 commit 71765d7

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/NamedQueryBinder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ public static void processNamedQuery(
4545

4646
for ( Object content : namedQueryBinding.getContent() ) {
4747
if ( String.class.isInstance( content ) ) {
48-
query = (String) content;
48+
String trimmed = ((String)content).trim();
49+
if (!"".equals(trimmed)) {
50+
query = trimmed;
51+
}
4952
}
5053
else {
51-
final JaxbHbmQueryParamType paramTypeBinding = (JaxbHbmQueryParamType) content;
54+
final JaxbHbmQueryParamType paramTypeBinding =
55+
(JaxbHbmQueryParamType)((JAXBElement)content).getValue();
5256
if ( parameterTypeMap == null ) {
5357
parameterTypeMap = new HashMap<String,String>();
5458
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.hibernate.test.hbm.query;
2+
3+
import java.io.StringReader;
4+
5+
import org.hibernate.cfg.Configuration;
6+
import org.hibernate.engine.jdbc.ReaderInputStream;
7+
import org.hibernate.testing.TestForIssue;
8+
import org.hibernate.testing.junit4.BaseUnitTestCase;
9+
import org.junit.Test;
10+
11+
/**
12+
* @author Koen Aers
13+
*/
14+
@TestForIssue( jiraKey = "HHH-10223" )
15+
public class NamedQueryTest extends BaseUnitTestCase {
16+
17+
private static String NAMED_QUERY_HBM_XML =
18+
"<hibernate-mapping package='org.hibernate.test.hbm.query'> "+
19+
" <class name='NamedQueryTest$Bar'> "+
20+
" <id name='id'> "+
21+
" <generator class='sequence'/> "+
22+
" </id> "+
23+
" <query name='findByFoo'> "+
24+
" <query-param name='foo' type='string'/> "+
25+
" from NamedQueryTest$Bar where foo like :foo "+
26+
" </query> "+
27+
" </class> "+
28+
"</hibernate-mapping> ";
29+
30+
@Test
31+
public void testQuery() {
32+
Configuration cfg = new Configuration();
33+
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
34+
cfg.addInputStream(new ReaderInputStream(new StringReader(NAMED_QUERY_HBM_XML)));
35+
cfg.buildSessionFactory();
36+
}
37+
38+
public class Bar {
39+
private Integer id;
40+
private String foo;
41+
public Integer getId() { return id; }
42+
public void setId(Integer id) { this.id = id; }
43+
public String getFoo() { return foo; }
44+
public void setFoo(String foo) { this.foo = foo; }
45+
}
46+
47+
}

0 commit comments

Comments
 (0)