HHH-10223: Element 'query-param' in *.hbm.xml files causes ClassCastException

This commit is contained in:
Koen Aers 2015-12-03 14:55:45 +01:00
parent 0638a5449c
commit 71765d7bd2
2 changed files with 53 additions and 2 deletions

View File

@ -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<String,String>();
}

View File

@ -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 =
"<hibernate-mapping package='org.hibernate.test.hbm.query'> "+
" <class name='NamedQueryTest$Bar'> "+
" <id name='id'> "+
" <generator class='sequence'/> "+
" </id> "+
" <query name='findByFoo'> "+
" <query-param name='foo' type='string'/> "+
" from NamedQueryTest$Bar where foo like :foo "+
" </query> "+
" </class> "+
"</hibernate-mapping> ";
@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; }
}
}