From 9e89826f8fde304767dd93013a8f1968f7c0e2bf Mon Sep 17 00:00:00 2001 From: Koen Aers Date: Tue, 29 Dec 2015 13:19:31 +0000 Subject: [PATCH] HHH-10405: elements of are not handled properly when building metadata - Solution --- .../source/internal/hbm/NamedQueryBinder.java | 31 +++++++++++++++++-- .../engine/spi/NamedSQLQueryDefinition.java | 4 +++ 2 files changed, 32 insertions(+), 3 deletions(-) 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 9c5d4f5151..86ab810fc8 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 @@ -6,9 +6,12 @@ */ package org.hibernate.boot.model.source.internal.hbm; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; + import javax.xml.bind.JAXBElement; import org.hibernate.MappingException; @@ -22,7 +25,10 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNativeQueryScalarReturnType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmQueryParamType; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSynchronizeType; import org.hibernate.cfg.SecondPass; +import org.hibernate.engine.ResultSetMappingDefinition; +import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn; import org.hibernate.engine.spi.NamedQueryDefinitionBuilder; +import org.hibernate.engine.spi.NamedSQLQueryDefinition; import org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder; import org.hibernate.internal.util.StringHelper; @@ -169,9 +175,28 @@ public class NamedQueryBinder { new SecondPass() { @Override public void doSecondPass(Map persistentClasses) throws MappingException { - context.getMetadataCollector().addResultSetMapping( - ResultSetMappingBinder.bind( implicitResultSetMappingDefinition, context ) - ); + ResultSetMappingDefinition resultSetMappingDefinition = + ResultSetMappingBinder.bind(implicitResultSetMappingDefinition, context); + context.getMetadataCollector().addResultSetMapping(resultSetMappingDefinition); + NativeSQLQueryReturn[] newQueryReturns = resultSetMappingDefinition.getQueryReturns(); + if (newQueryReturns != null && newQueryReturns.length > 0) { + List queryReturnList = + new ArrayList(); + NamedSQLQueryDefinition queryDefinition = + context.getMetadataCollector().getNamedNativeQueryDefinition(queryName); + NativeSQLQueryReturn[] existingQueryReturns = queryDefinition.getQueryReturns(); + if (existingQueryReturns != null && existingQueryReturns.length > 0) { + for (NativeSQLQueryReturn queryReturn : existingQueryReturns) { + queryReturnList.add(queryReturn); + } + } + for (NativeSQLQueryReturn queryReturn : newQueryReturns) { + queryReturnList.add(queryReturn); + } + NativeSQLQueryReturn[] allQueryReturns = + queryReturnList.toArray(new NativeSQLQueryReturn[queryReturnList.size()]); + queryDefinition.setQueryReturns(allQueryReturns); + } } } ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/NamedSQLQueryDefinition.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/NamedSQLQueryDefinition.java index 0965cd89d3..c1d6527993 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/NamedSQLQueryDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/NamedSQLQueryDefinition.java @@ -222,4 +222,8 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition { getQueryReturns() ); } + + public void setQueryReturns(NativeSQLQueryReturn[] queryReturns) { + this.queryReturns = queryReturns; + } }