mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-18 17:15:02 +00:00
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 org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||||
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.metamodel.mapping.SelectableConsumer;
|
import org.hibernate.metamodel.mapping.SelectableConsumer;
|
||||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||||
import org.hibernate.query.NativeQuery;
|
import org.hibernate.query.NativeQuery;
|
||||||
@ -96,10 +97,7 @@ public Fetch buildFetch(
|
|||||||
creationStateImpl
|
creationStateImpl
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else if ( attributeMapping instanceof ToOneAttributeMapping ) {
|
||||||
// Not sure if this fetch builder can also be used with other attribute mappings
|
|
||||||
assert attributeMapping instanceof ToOneAttributeMapping;
|
|
||||||
|
|
||||||
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
|
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
|
||||||
toOneAttributeMapping.getForeignKeyDescriptor().visitKeySelectables( selectableConsumer );
|
toOneAttributeMapping.getForeignKeyDescriptor().visitKeySelectables( selectableConsumer );
|
||||||
return parent.generateFetchableFetch(
|
return parent.generateFetchableFetch(
|
||||||
@ -111,6 +109,19 @@ public Fetch buildFetch(
|
|||||||
creationStateImpl
|
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
|
@Override
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
import org.hibernate.query.results.complete.CompleteResultBuilderCollectionStandard;
|
import org.hibernate.query.results.complete.CompleteResultBuilderCollectionStandard;
|
||||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||||
import org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard;
|
import org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard;
|
||||||
|
import org.hibernate.type.CollectionType;
|
||||||
import org.hibernate.type.EntityType;
|
import org.hibernate.type.EntityType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
@ -319,15 +320,26 @@ private DynamicResultBuilderEntityStandard createSuffixedResultBuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ( String propertyName : loadable.getPropertyNames() ) {
|
for ( String propertyName : loadable.getPropertyNames() ) {
|
||||||
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases(
|
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases( propertyName, suffix );
|
||||||
propertyName,
|
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
|
suffix
|
||||||
);
|
);
|
||||||
if ( columnAliases.length != 0 ) {
|
}
|
||||||
resultBuilderEntity.addProperty(
|
resultBuilderEntity.addProperty( propertyName, keyColumnAliases );
|
||||||
propertyName,
|
}
|
||||||
columnAliases
|
}
|
||||||
);
|
else {
|
||||||
|
resultBuilderEntity.addProperty( propertyName, columnAliases );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultBuilderEntity;
|
return resultBuilderEntity;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//$Id: Account.java 4399 2004-08-21 08:43:20Z oneovthafew $
|
//$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 $
|
//$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 $
|
//$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.HashSet;
|
||||||
import java.util.Set;
|
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">
|
<class name="Person" table="PROPREF_PERS">
|
||||||
<id name="id">
|
<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 $
|
//$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.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -4,7 +4,7 @@
|
|||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,7 +37,7 @@
|
|||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
@DomainModel(
|
@DomainModel(
|
||||||
xmlMappings = "org/hibernate/test/propertyref/basic/Person.hbm.xml"
|
xmlMappings = "org/hibernate/orm/test/propertyref/basic/Person.hbm.xml"
|
||||||
|
|
||||||
)
|
)
|
||||||
@SessionFactory(
|
@SessionFactory(
|
Loading…
x
Reference in New Issue
Block a user