HHH-10405: <return> elements of <sql-query> are not handled properly when building metadata - Solution
This commit is contained in:
parent
bacb67fe73
commit
eed0fe8b28
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -222,4 +222,8 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
|||
getQueryReturns()
|
||||
);
|
||||
}
|
||||
|
||||
public void setQueryReturns(NativeSQLQueryReturn[] queryReturns) {
|
||||
this.queryReturns = queryReturns;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue