Skip to content

Commit

Permalink
HHH-18629 Fix inconsistent column alias generated while result class …
Browse files Browse the repository at this point in the history
…is used for placeholder
  • Loading branch information
quaff committed Sep 18, 2024
1 parent 0684c6e commit 34ca6d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,8 @@ else if ( List.class.equals( resultClass ) ) {
query.setTupleTransformer( NativeQueryListTransformer.INSTANCE );
}
else if ( getFactory().getMappingMetamodel().isEntityClass( resultClass ) ) {
query.addEntity( resultClass, LockMode.READ );
// use empty string as tableAlias to identify it as implicit
query.addEntity( "", resultClass, LockMode.READ );
}
else if ( resultClass != Object.class && resultClass != Object[].class ) {
if ( isClass( resultClass ) && !hasJavaTypeDescriptor( resultClass ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public interface ResultSetMapping extends JdbcValuesMappingProducer {
*/
void addResultBuilder(ResultBuilder resultBuilder);

/**
* Remove a builder
*/
void removeResultBuilder(ResultBuilder resultBuilder);

/**
* Add a legacy fetch builder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public void addResultBuilder(ResultBuilder resultBuilder) {
resultBuilders.add( resultBuilder );
}

@Override
public void removeResultBuilder(ResultBuilder resultBuilder) {
resultBuilders.remove( resultBuilder );
}

@Override
public void addLegacyFetchBuilder(DynamicFetchBuilderLegacy fetchBuilder) {
final Map<String, DynamicFetchBuilderLegacy> existingFetchBuildersByOwner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,23 @@ public NativeQueryImplementor<R> addScalar(int position, Class<?> type) {
}

protected NativeQueryImplementor<R> registerBuilder(ResultBuilder builder) {
// remove implicit ResultBuilder if explicit one provided
if ( builder instanceof DynamicResultBuilderEntityCalculated dynamicBuilder ) {
ResultBuilder implicitResultBuilder = null;
for ( ResultBuilder existing : resultSetMapping.getResultBuilders() ) {
if ( existing instanceof DynamicResultBuilderEntityCalculated existingDynamicBuilder ) {
if ( "".equals( existingDynamicBuilder.getTableAlias() ) // implicit
&& existingDynamicBuilder.getNavigablePath().equals( dynamicBuilder.getNavigablePath() )
&& existingDynamicBuilder.getEntityMapping().equals( dynamicBuilder.getEntityMapping() ) ) {
implicitResultBuilder = existingDynamicBuilder;
break;
}
}
}
if ( implicitResultBuilder != null ) {
resultSetMapping.removeResultBuilder( implicitResultBuilder );
}
}
resultSetMapping.addResultBuilder( builder );
return this;
}
Expand Down

0 comments on commit 34ca6d4

Please sign in to comment.