Resolve collection key selection expressions for delayed collection fetches of dynamic fetch builders with the suffixed column alias of the referenced property name
This commit is contained in:
parent
44babcb880
commit
5b24b171da
|
@ -12,6 +12,7 @@ import java.util.function.BiFunction;
|
|||
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.SelectableConsumer;
|
||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
|
@ -96,10 +97,7 @@ public class DynamicFetchBuilderStandard
|
|||
creationStateImpl
|
||||
);
|
||||
}
|
||||
else {
|
||||
// Not sure if this fetch builder can also be used with other attribute mappings
|
||||
assert attributeMapping instanceof ToOneAttributeMapping;
|
||||
|
||||
else if ( attributeMapping instanceof ToOneAttributeMapping ) {
|
||||
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
|
||||
toOneAttributeMapping.getForeignKeyDescriptor().visitKeySelectables( selectableConsumer );
|
||||
return parent.generateFetchableFetch(
|
||||
|
@ -111,6 +109,19 @@ public class DynamicFetchBuilderStandard
|
|||
creationStateImpl
|
||||
);
|
||||
}
|
||||
else {
|
||||
assert attributeMapping instanceof PluralAttributeMapping;
|
||||
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) attributeMapping;
|
||||
pluralAttributeMapping.getKeyDescriptor().visitTargetSelectables( selectableConsumer );
|
||||
return parent.generateFetchableFetch(
|
||||
attributeMapping,
|
||||
fetchPath,
|
||||
FetchTiming.DELAYED,
|
||||
false,
|
||||
null,
|
||||
creationStateImpl
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.hibernate.query.results.ResultSetMappingImpl;
|
|||
import org.hibernate.query.results.complete.CompleteResultBuilderCollectionStandard;
|
||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||
import org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard;
|
||||
import org.hibernate.type.CollectionType;
|
||||
import org.hibernate.type.EntityType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -319,15 +320,26 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
}
|
||||
|
||||
for ( String propertyName : loadable.getPropertyNames() ) {
|
||||
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases(
|
||||
propertyName,
|
||||
suffix
|
||||
);
|
||||
if ( columnAliases.length != 0 ) {
|
||||
resultBuilderEntity.addProperty(
|
||||
propertyName,
|
||||
columnAliases
|
||||
);
|
||||
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases( propertyName, suffix );
|
||||
if ( columnAliases.length == 0 ) {
|
||||
final Type propertyType = loadable.getPropertyType( propertyName );
|
||||
if ( propertyType instanceof CollectionType ) {
|
||||
final CollectionType collectionType = (CollectionType) propertyType;
|
||||
final String[] keyColumnAliases;
|
||||
if ( collectionType.useLHSPrimaryKey() ) {
|
||||
keyColumnAliases = identifierAliases;
|
||||
}
|
||||
else {
|
||||
keyColumnAliases = loadable.getSubclassPropertyColumnAliases(
|
||||
collectionType.getLHSPropertyName(),
|
||||
suffix
|
||||
);
|
||||
}
|
||||
resultBuilderEntity.addProperty( propertyName, keyColumnAliases );
|
||||
}
|
||||
}
|
||||
else {
|
||||
resultBuilderEntity.addProperty( propertyName, columnAliases );
|
||||
}
|
||||
}
|
||||
return resultBuilderEntity;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Account.java 4399 2004-08-21 08:43:20Z oneovthafew $
|
||||
package org.hibernate.test.propertyref.basic;
|
||||
package org.hibernate.orm.test.propertyref.basic;
|
||||
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Address.java 4390 2004-08-20 07:54:48Z oneovthafew $
|
||||
package org.hibernate.test.propertyref.basic;
|
||||
package org.hibernate.orm.test.propertyref.basic;
|
||||
|
||||
|
||||
/**
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Group.java 7589 2005-07-21 01:56:42Z oneovthafew $
|
||||
package org.hibernate.test.propertyref.basic;
|
||||
package org.hibernate.orm.test.propertyref.basic;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.propertyref.basic">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.propertyref.basic">
|
||||
|
||||
<class name="Person" table="PROPREF_PERS">
|
||||
<id name="id">
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Person.java 10396 2006-09-01 08:48:02 -0500 (Fri, 01 Sep 2006) steve.ebersole@jboss.com $
|
||||
package org.hibernate.test.propertyref.basic;
|
||||
package org.hibernate.orm.test.propertyref.basic;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.propertyref.basic;
|
||||
package org.hibernate.orm.test.propertyref.basic;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -37,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
* @author Gavin King
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/test/propertyref/basic/Person.hbm.xml"
|
||||
xmlMappings = "org/hibernate/orm/test/propertyref/basic/Person.hbm.xml"
|
||||
|
||||
)
|
||||
@SessionFactory(
|
Loading…
Reference in New Issue