HHH-10405: <return> elements of <sql-query> are not handled properly when building metadata - Solution

This commit is contained in:
Koen Aers 2015-12-29 13:19:31 +00:00 committed by Andrea Boriero
parent e9834f4810
commit 9e89826f8f
2 changed files with 32 additions and 3 deletions

View File

@ -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<NativeSQLQueryReturn> queryReturnList =
new ArrayList<NativeSQLQueryReturn>();
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);
}
}
}
);

View File

@ -222,4 +222,8 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
getQueryReturns()
);
}
public void setQueryReturns(NativeSQLQueryReturn[] queryReturns) {
this.queryReturns = queryReturns;
}
}