From 1b62f92c0778d91064bf43b17b8773c1e3831d8c Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 22 Oct 2012 17:52:19 +0800 Subject: [PATCH] HHH-6109 bind sql result mapping and named query --- .../source/hbm/HibernateMappingProcessor.java | 40 +++++++++++++------ .../test/annotations/loader/LoaderTest.java | 1 - 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java index 496f91f657..4f4a14c290 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java @@ -34,6 +34,8 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; +import javax.xml.bind.JAXBElement; + import org.jboss.logging.Logger; import org.hibernate.CacheMode; @@ -775,13 +777,20 @@ public class HibernateMappingProcessor { String query = ""; boolean isQueryDefined = false; for ( Serializable obj : contents ) { - if ( JaxbQueryParamElement.class.isInstance( obj ) ) { + if(obj == null){ + continue; + } + else if ( JaxbQueryParamElement.class.isInstance( obj ) ) { JaxbQueryParamElement element = JaxbQueryParamElement.class.cast( obj ); queryParam.put( element.getName(), element.getType() ); } else if ( String.class.isInstance( obj ) ) { if ( !isQueryDefined ) { - query = obj.toString(); + if( StringHelper.isNotEmpty( obj.toString().trim() )){ + query = obj.toString().trim(); + isQueryDefined = true; + } + } else { throw new MappingException( @@ -816,23 +825,30 @@ public class HibernateMappingProcessor { @Override protected void parseExtra(String queryName, Serializable obj, NamedQueryDefinitionBuilder builder) { + if ( !JAXBElement.class.isInstance( obj ) ) { + return; + } NamedSQLQueryDefinitionBuilder sqlBuilder = NamedSQLQueryDefinitionBuilder.class.cast( builder ); - if ( JaxbSynchronizeElement.class.isInstance( obj ) ) { - JaxbSynchronizeElement element = JaxbSynchronizeElement.class.cast( obj ); + JAXBElement jaxbElement = JAXBElement.class.cast( obj ); + Class targetType = jaxbElement.getDeclaredType(); + Object value = jaxbElement.getValue(); + if ( JaxbSynchronizeElement.class == targetType ) { + JaxbSynchronizeElement element = JaxbSynchronizeElement.class.cast( value ); synchronizedTables.add( element.getTable() ); } - else if ( JaxbLoadCollectionElement.class.isInstance( obj ) ) { - loadCollectionElements.add( JaxbLoadCollectionElement.class.cast( obj ) ); + else if ( JaxbLoadCollectionElement.class == targetType ) { + loadCollectionElements.add( JaxbLoadCollectionElement.class.cast( value ) ); } - else if ( JaxbReturnScalarElement.class.isInstance( obj ) ) { - returnScalarElements.add( JaxbReturnScalarElement.class.cast( obj ) ); + else if ( JaxbReturnScalarElement.class == targetType ) { + returnScalarElements.add( JaxbReturnScalarElement.class.cast( value ) ); } - else if ( JaxbReturnElement.class.isInstance( obj ) ) { - returnElements.add( JaxbReturnElement.class.cast( obj ) ); + else if ( JaxbReturnElement.class == targetType ) { + returnElements.add( JaxbReturnElement.class.cast( value ) ); } - else if ( JaxbReturnJoinElement.class.isInstance( obj ) ) { - returnJoinElements.add( JaxbReturnJoinElement.class.cast( obj ) ); + else if ( JaxbReturnJoinElement.class == targetType ) { + returnJoinElements.add( JaxbReturnJoinElement.class.cast( value ) ); } + } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java index 33a655d7d6..e3da119417 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java @@ -38,7 +38,6 @@ import static org.junit.Assert.assertEquals; /** * @author Emmanuel Bernard */ -@FailureExpectedWithNewMetamodel public class LoaderTest extends BaseCoreFunctionalTestCase { @Override protected String[] getXmlFiles() {