Fix HBM return-join handling
This commit is contained in:
parent
95a34e2895
commit
75f4e635f2
|
@ -29,7 +29,6 @@ import org.hibernate.internal.util.collections.CollectionHelper;
|
|||
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
|
@ -161,7 +160,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
|||
);
|
||||
}
|
||||
|
||||
final String ownerTableAlias = fullPropertyPath.substring( 0, firstDot - 1 );
|
||||
final String ownerTableAlias = fullPropertyPath.substring( 0, firstDot );
|
||||
final String propertyPath = fullPropertyPath.substring( firstDot + 1 );
|
||||
final String tableAlias = jaxbHbmJoin.getAlias();
|
||||
|
||||
|
@ -394,7 +393,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
|||
);
|
||||
}
|
||||
|
||||
final Map<String,FetchMemento> fetchDescriptorMap = new HashMap<>();
|
||||
final Map<String, FetchMemento> fetchDescriptorMap = new HashMap<>();
|
||||
propertyFetchDescriptors.forEach(
|
||||
hbmFetchDescriptor -> fetchDescriptorMap.put(
|
||||
hbmFetchDescriptor.getFetchablePath(),
|
||||
|
@ -403,6 +402,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
|||
);
|
||||
|
||||
return new ResultMementoEntityStandard(
|
||||
tableAlias,
|
||||
entityDescriptor,
|
||||
lockMode,
|
||||
discriminatorMemento,
|
||||
|
@ -462,7 +462,10 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
|||
(fetchableName, joinDescriptor) -> {
|
||||
final boolean added = processedFetchableNames.add( fetchableName );
|
||||
|
||||
if ( ! added ) {
|
||||
if ( added ) {
|
||||
propertyFetchDescriptors.add( joinDescriptor );
|
||||
}
|
||||
else {
|
||||
// the fetch is most likely more complete of a mapping so replace the original
|
||||
for ( int i = 0; i < propertyFetchDescriptors.size(); i++ ) {
|
||||
final HbmFetchDescriptor propertyFetchDescriptor = propertyFetchDescriptors.get( i );
|
||||
|
@ -587,7 +590,7 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
|||
);
|
||||
}
|
||||
|
||||
this.ownerTableAlias = fullPropertyPath.substring( 0, firstDot - 1 );
|
||||
this.ownerTableAlias = fullPropertyPath.substring( 0, firstDot );
|
||||
|
||||
this.propertyPath = fullPropertyPath.substring( firstDot + 1 );
|
||||
this.tableAlias = hbmJoinReturn.getAlias();
|
||||
|
@ -628,9 +631,20 @@ public class HbmResultSetMappingDescriptor implements NamedResultSetMappingDescr
|
|||
|
||||
applyFetchJoins( joinDescriptorsAccess, tableAlias, propertyFetchDescriptors );
|
||||
|
||||
final Map<String, FetchMemento> fetchDescriptorMap = new HashMap<>();
|
||||
propertyFetchDescriptors.forEach(
|
||||
hbmFetchDescriptor -> fetchDescriptorMap.put(
|
||||
hbmFetchDescriptor.getFetchablePath(),
|
||||
hbmFetchDescriptor.resolve( resolutionContext )
|
||||
)
|
||||
);
|
||||
memento = new FetchMementoHbmStandard(
|
||||
thisAsParentMemento.getNavigablePath(),
|
||||
ownerTableAlias,
|
||||
tableAlias,
|
||||
lockMode,
|
||||
thisAsParentMemento,
|
||||
fetchDescriptorMap,
|
||||
(Fetchable) thisAsParentMemento.getFetchableContainer()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,34 +6,50 @@
|
|||
*/
|
||||
package org.hibernate.query.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.named.FetchMemento;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||
import org.hibernate.sql.results.graph.Fetchable;
|
||||
import org.hibernate.sql.results.graph.FetchableContainer;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class FetchMementoHbmStandard implements FetchMemento {
|
||||
public class FetchMementoHbmStandard implements FetchMemento, FetchMemento.Parent {
|
||||
public interface FetchParentMemento {
|
||||
NavigablePath getNavigablePath();
|
||||
FetchableContainer getFetchableContainer();
|
||||
}
|
||||
|
||||
private final NavigablePath navigablePath;
|
||||
|
||||
private final String ownerTableAlias;
|
||||
private final String tableAlias;
|
||||
private final LockMode lockMode;
|
||||
private final FetchParentMemento parent;
|
||||
private final Map<String, FetchMemento> fetchMementoMap;
|
||||
private final Fetchable fetchable;
|
||||
|
||||
public FetchMementoHbmStandard(
|
||||
NavigablePath navigablePath,
|
||||
String ownerTableAlias,
|
||||
String tableAlias,
|
||||
LockMode lockMode,
|
||||
FetchParentMemento parent,
|
||||
Map<String, FetchMemento> fetchMementoMap,
|
||||
Fetchable fetchable) {
|
||||
this.navigablePath = navigablePath;
|
||||
this.ownerTableAlias = ownerTableAlias;
|
||||
this.tableAlias = tableAlias;
|
||||
this.lockMode = lockMode;
|
||||
this.parent = parent;
|
||||
this.fetchMementoMap = fetchMementoMap;
|
||||
this.fetchable = fetchable;
|
||||
}
|
||||
|
||||
|
@ -47,6 +63,20 @@ public class FetchMementoHbmStandard implements FetchMemento {
|
|||
Parent parent,
|
||||
Consumer<String> querySpaceConsumer,
|
||||
ResultSetMappingResolutionContext context) {
|
||||
return null;
|
||||
final Map<String, FetchBuilder> fetchBuilderMap = new HashMap<>();
|
||||
|
||||
fetchMementoMap.forEach(
|
||||
(attrName, fetchMemento) -> fetchBuilderMap.put(
|
||||
attrName,
|
||||
fetchMemento.resolve(this, querySpaceConsumer, context )
|
||||
)
|
||||
);
|
||||
return new DynamicFetchBuilderLegacy(
|
||||
tableAlias,
|
||||
ownerTableAlias,
|
||||
fetchable.getFetchableName(),
|
||||
new ArrayList<>(),
|
||||
fetchBuilderMap
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.hibernate.query.results.complete.CompleteResultBuilderEntityStandard;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ResultMementoEntityStandard implements ResultMementoEntity, FetchMemento.Parent {
|
||||
private final String tableAlias;
|
||||
private final NavigablePath navigablePath;
|
||||
private final EntityMappingType entityDescriptor;
|
||||
private final LockMode lockMode;
|
||||
|
@ -33,10 +34,12 @@ public class ResultMementoEntityStandard implements ResultMementoEntity, FetchMe
|
|||
private final Map<String, FetchMemento> fetchMementoMap;
|
||||
|
||||
public ResultMementoEntityStandard(
|
||||
String tableAlias,
|
||||
EntityMappingType entityDescriptor,
|
||||
LockMode lockMode,
|
||||
ResultMementoBasic discriminatorMemento,
|
||||
Map<String, FetchMemento> fetchMementoMap) {
|
||||
this.tableAlias = tableAlias;
|
||||
this.navigablePath = new NavigablePath( entityDescriptor.getEntityName() );
|
||||
this.entityDescriptor = entityDescriptor;
|
||||
this.lockMode = lockMode;
|
||||
|
@ -72,6 +75,7 @@ public class ResultMementoEntityStandard implements ResultMementoEntity, FetchMe
|
|||
);
|
||||
|
||||
return new CompleteResultBuilderEntityStandard(
|
||||
tableAlias,
|
||||
navigablePath,
|
||||
entityDescriptor,
|
||||
lockMode,
|
||||
|
|
|
@ -239,7 +239,7 @@ public class Builders {
|
|||
}
|
||||
|
||||
public static DynamicFetchBuilderLegacy fetch(String tableAlias, String ownerTableAlias, String joinPropertyName) {
|
||||
return new DynamicFetchBuilderLegacy( tableAlias, ownerTableAlias, joinPropertyName, null );
|
||||
return new DynamicFetchBuilderLegacy( tableAlias, ownerTableAlias, joinPropertyName, null, null );
|
||||
}
|
||||
|
||||
public static ResultBuilder implicitEntityResultBuilder(
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.query.results;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
|
@ -31,4 +32,7 @@ public interface FetchBuilder {
|
|||
NavigablePath fetchPath, JdbcValuesMetadata jdbcResultsMetadata,
|
||||
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
||||
DomainResultCreationState domainResultCreationState);
|
||||
|
||||
default void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.query.results;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
|
@ -27,4 +28,7 @@ public interface ResultBuilder {
|
|||
int resultPosition,
|
||||
BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver,
|
||||
DomainResultCreationState domainResultCreationState);
|
||||
|
||||
default void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.query.results.complete;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
|
@ -118,4 +119,9 @@ public class CompleteResultBuilderEntityJpa implements CompleteResultBuilderEnti
|
|||
impl.popExplicitFetchMementoResolver();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
explicitFetchBuilderMap.forEach( consumer );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
package org.hibernate.query.results.complete;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
|
@ -25,7 +27,8 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
|||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CompleteResultBuilderEntityStandard implements CompleteResultBuilderEntityValued {
|
||||
public class CompleteResultBuilderEntityStandard implements CompleteResultBuilderEntityValued, NativeQuery.RootReturn {
|
||||
private final String tableAlias;
|
||||
private final NavigablePath navigablePath;
|
||||
private final EntityMappingType entityDescriptor;
|
||||
private final LockMode lockMode;
|
||||
|
@ -33,11 +36,13 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde
|
|||
private final HashMap<String, FetchBuilder> explicitFetchBuilderMap;
|
||||
|
||||
public CompleteResultBuilderEntityStandard(
|
||||
String tableAlias,
|
||||
NavigablePath navigablePath,
|
||||
EntityMappingType entityDescriptor,
|
||||
LockMode lockMode,
|
||||
ResultBuilderBasicValued discriminatorResultBuilder,
|
||||
HashMap<String, FetchBuilder> explicitFetchBuilderMap) {
|
||||
this.tableAlias = tableAlias;
|
||||
this.navigablePath = navigablePath;
|
||||
this.entityDescriptor = entityDescriptor;
|
||||
this.lockMode = lockMode;
|
||||
|
@ -55,6 +60,46 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde
|
|||
return entityDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableAlias() {
|
||||
return tableAlias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDiscriminatorAlias() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityMappingType getEntityMapping() {
|
||||
return entityDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQuery.RootReturn setLockMode(LockMode lockMode) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQuery.RootReturn addIdColumnAliases(String... aliases) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQuery.RootReturn setDiscriminatorAlias(String columnAlias) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQuery.RootReturn addProperty(String propertyName, String columnAlias) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeQuery.ReturnProperty addProperty(String propertyName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityResult buildResult(
|
||||
JdbcValuesMetadata jdbcResultsMetadata,
|
||||
|
@ -107,4 +152,9 @@ public class CompleteResultBuilderEntityStandard implements CompleteResultBuilde
|
|||
impl.popExplicitFetchMementoResolver();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
explicitFetchBuilderMap.forEach( consumer );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,9 @@ public abstract class AbstractFetchBuilderContainer<T extends AbstractFetchBuild
|
|||
}
|
||||
|
||||
public void addFetchBuilder(String propertyName, DynamicFetchBuilder fetchBuilder) {
|
||||
if ( fetchBuilderMap == null ) {
|
||||
fetchBuilderMap = new HashMap<>();
|
||||
}
|
||||
fetchBuilderMap.put( propertyName, fetchBuilder );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.query.results.dynamic;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
|
@ -18,6 +20,7 @@ import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
|||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.results.DomainResultCreationStateImpl;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
import org.hibernate.query.results.ResultsHelper;
|
||||
import org.hibernate.query.results.SqlSelectionImpl;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
|
@ -46,17 +49,20 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
|||
private final String fetchableName;
|
||||
|
||||
private final List<String> columnNames;
|
||||
private final Map<String, FetchBuilder> fetchBuilderMap;
|
||||
private final DynamicResultBuilderEntityStandard resultBuilderEntity;
|
||||
|
||||
public DynamicFetchBuilderLegacy(
|
||||
String tableAlias,
|
||||
String ownerTableAlias,
|
||||
String fetchableName,
|
||||
List<String> columnNames) {
|
||||
List<String> columnNames,
|
||||
Map<String, FetchBuilder> fetchBuilderMap) {
|
||||
this.tableAlias = tableAlias;
|
||||
this.ownerTableAlias = ownerTableAlias;
|
||||
this.fetchableName = fetchableName;
|
||||
this.columnNames = columnNames;
|
||||
this.fetchBuilderMap = fetchBuilderMap;
|
||||
this.resultBuilderEntity = null;
|
||||
}
|
||||
|
||||
|
@ -65,11 +71,13 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
|||
String ownerTableAlias,
|
||||
String fetchableName,
|
||||
List<String> columnNames,
|
||||
Map<String, FetchBuilder> fetchBuilderMap,
|
||||
DynamicResultBuilderEntityStandard resultBuilderEntity) {
|
||||
this.tableAlias = tableAlias;
|
||||
this.ownerTableAlias = ownerTableAlias;
|
||||
this.fetchableName = fetchableName;
|
||||
this.columnNames = columnNames;
|
||||
this.fetchBuilderMap = fetchBuilderMap;
|
||||
this.resultBuilderEntity = resultBuilderEntity;
|
||||
}
|
||||
|
||||
|
@ -199,4 +207,9 @@ public class DynamicFetchBuilderLegacy implements DynamicFetchBuilder, NativeQue
|
|||
public NativeQuery.ReturnProperty addProperty(String propertyName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
fetchBuilderMap.forEach( consumer );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class DynamicFetchBuilderStandard
|
|||
state -> {
|
||||
final int resultSetPosition = jdbcResultsMetadata.resolveColumnPosition( columnAlias );
|
||||
final int valuesArrayPosition = resultSetPosition - 1;
|
||||
return new SqlSelectionImpl( valuesArrayPosition, (BasicValuedMapping) selectableMapping );
|
||||
return new SqlSelectionImpl( valuesArrayPosition, selectableMapping.getJdbcMapping() );
|
||||
}
|
||||
),
|
||||
selectableMapping.getJdbcMapping().getMappedJavaTypeDescriptor(),
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.query.results.implicit;
|
|||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -120,4 +121,9 @@ public class ImplicitFetchBuilderEmbeddable implements ImplicitFetchBuilder {
|
|||
public String toString() {
|
||||
return "ImplicitFetchBuilderEmbeddable(" + fetchPath + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
fetchBuilders.forEach( (k, v) -> consumer.accept( k.getUnaliasedLocalName(), v ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.query.results.implicit;
|
|||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -120,6 +121,11 @@ public class ImplicitFetchBuilderEntity implements ImplicitFetchBuilder {
|
|||
return fetch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFetchBuilders(BiConsumer<String, FetchBuilder> consumer) {
|
||||
fetchBuilders.forEach( (k, v) -> consumer.accept( k.getUnaliasedLocalName(), v ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ImplicitFetchBuilderEntity(" + fetchPath + ")";
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.persister.entity.Joinable;
|
|||
import org.hibernate.persister.entity.SQLLoadable;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.query.NavigablePath;
|
||||
import org.hibernate.query.results.FetchBuilder;
|
||||
import org.hibernate.query.results.ResultSetMapping;
|
||||
import org.hibernate.query.results.ResultSetMappingImpl;
|
||||
import org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy;
|
||||
|
@ -104,6 +105,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
if ( resultBuilder instanceof NativeQuery.RootReturn ) {
|
||||
final NativeQuery.RootReturn rootReturn = (NativeQuery.RootReturn) resultBuilder;
|
||||
alias2Return.put( rootReturn.getTableAlias(), rootReturn );
|
||||
resultBuilder.visitFetchBuilders( this::processFetchBuilder );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -122,6 +124,18 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
return this;
|
||||
}
|
||||
|
||||
private void processFetchBuilder(String attributeName, FetchBuilder fetchBuilder) {
|
||||
if ( fetchBuilder instanceof DynamicFetchBuilderLegacy ) {
|
||||
resultSetMapping.addLegacyFetchBuilder( (DynamicFetchBuilderLegacy) fetchBuilder );
|
||||
}
|
||||
else if ( fetchBuilder instanceof NativeQuery.FetchReturn ) {
|
||||
final NativeQuery.FetchReturn fetchReturn = (NativeQuery.FetchReturn) fetchBuilder;
|
||||
alias2Return.put( fetchReturn.getTableAlias(), fetchReturn );
|
||||
alias2OwnerAlias.put( fetchReturn.getTableAlias(), fetchReturn.getOwnerAlias() );
|
||||
}
|
||||
fetchBuilder.visitFetchBuilders( this::processFetchBuilder );
|
||||
}
|
||||
|
||||
public ResultSetMapping generateResultMapping(boolean queryHadAliases) {
|
||||
if ( !queryHadAliases ) {
|
||||
return this.resultSetMapping;
|
||||
|
@ -200,7 +214,15 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
columnNames = Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
columnNames = Arrays.asList( collectionPersister.getKeyColumnAliases( suffix ) );
|
||||
final String collectionSuffix = alias2CollectionSuffix.get( fetchBuilder.getTableAlias() );
|
||||
final String[] keyColumnAliases = collectionPersister.getKeyColumnAliases( collectionSuffix );
|
||||
columnNames = Arrays.asList( keyColumnAliases );
|
||||
if ( collectionPersister.hasIndex() ) {
|
||||
resultBuilderEntity.addProperty(
|
||||
"{key}", // That's what BasicValuedCollectionPart returns..
|
||||
collectionPersister.getIndexColumnAliases( collectionSuffix )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -213,6 +235,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
fetchBuilder.getOwnerAlias(),
|
||||
fetchBuilder.getFetchableName(),
|
||||
columnNames,
|
||||
Collections.emptyMap(),
|
||||
resultBuilderEntity
|
||||
)
|
||||
);
|
||||
|
@ -256,8 +279,12 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
navigablePath
|
||||
);
|
||||
|
||||
resultBuilderEntity.addIdColumnAliases( loadable.getIdentifierAliases( suffix ) );
|
||||
final String[] identifierAliases = loadable.getIdentifierAliases( suffix );
|
||||
resultBuilderEntity.addIdColumnAliases( identifierAliases );
|
||||
resultBuilderEntity.setDiscriminatorAlias( loadable.getDiscriminatorAlias( suffix ) );
|
||||
if ( loadable.hasIdentifierProperty() ) {
|
||||
resultBuilderEntity.addProperty( loadable.getIdentifierPropertyName(), identifierAliases );
|
||||
}
|
||||
|
||||
for ( String propertyName : loadable.getPropertyNames() ) {
|
||||
final String[] columnAliases = loadable.getSubclassPropertyColumnAliases(
|
||||
|
@ -384,7 +411,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
|
|||
|
||||
// If this return's alias has not been processed yet, do so before further processing of this return
|
||||
if ( !alias2Persister.containsKey( ownerAlias ) ) {
|
||||
processReturn( alias2Return.get(ownerAlias) );
|
||||
processReturn( alias2Return.get( ownerAlias ) );
|
||||
}
|
||||
|
||||
SQLLoadable ownerPersister = ( SQLLoadable ) alias2Persister.get( ownerAlias );
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -7,7 +7,7 @@
|
|||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.extralazy">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.extralazy">
|
||||
<class name="Child" >
|
||||
<id name="id" >
|
||||
<column name="ID" length="32" />
|
|
@ -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.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Document.java 7635 2005-07-24 23:04:30Z oneovthafew $
|
||||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
|
||||
public class Document {
|
|
@ -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.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
|
@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = {
|
||||
"org/hibernate/test/extralazy/UserGroup.hbm.xml"
|
||||
"org/hibernate/orm/test/extralazy/UserGroup.hbm.xml"
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
|
@ -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.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -36,9 +36,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
annotatedClasses = { School.class, Student.class, Championship.class },
|
||||
xmlMappings =
|
||||
{
|
||||
"org/hibernate/test/extralazy/UserGroup.hbm.xml",
|
||||
"org/hibernate/test/extralazy/Parent.hbm.xml",
|
||||
"org/hibernate/test/extralazy/Child.hbm.xml"
|
||||
"org/hibernate/orm/test/extralazy/UserGroup.hbm.xml",
|
||||
"org/hibernate/orm/test/extralazy/Parent.hbm.xml",
|
||||
"org/hibernate/orm/test/extralazy/Child.hbm.xml"
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
|
@ -269,7 +269,7 @@ public class ExtraLazyTest {
|
|||
session.persist( turin );
|
||||
session.flush();
|
||||
session.clear();
|
||||
List results = session.getNamedQuery( "userData" ).setParameter( "uname", "%in" ).list();
|
||||
List results = session.getNamedQuery( "userSessionData" ).setParameter( "uname", "%in" ).list();
|
||||
assertThat( results.size(), is( 2 ) );
|
||||
gavin = (User) results.get( 0 );
|
||||
assertThat( gavin.getName(), is( "gavin" ) );
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: Group.java 7628 2005-07-24 06:55:01Z oneovthafew $
|
||||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping package="org.hibernate.test.extralazy">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.extralazy">
|
||||
<class name="Parent" >
|
||||
|
||||
<!-- properties inherited from Adapter -->
|
|
@ -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.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: SessionAttribute.java 7628 2005-07-24 06:55:01Z oneovthafew $
|
||||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
|
||||
import java.util.Objects;
|
||||
import javax.persistence.Entity;
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
//$Id: User.java 7635 2005-07-24 23:04:30Z oneovthafew $
|
||||
package org.hibernate.test.extralazy;
|
||||
package org.hibernate.orm.test.extralazy;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.extralazy">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.extralazy">
|
||||
|
||||
<class name="Group" table="groups_">
|
||||
<id name="name"/>
|
||||
|
@ -69,5 +69,4 @@
|
|||
where u.name like :uname
|
||||
</sql-query>
|
||||
|
||||
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue