-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18610 - Native query single table inheritance does not set/discover column positions for reading result set #9009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e794f55
4e0b9a6
e3c6438
0cdf181
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,11 @@ | |
| package org.hibernate.persister.entity; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.hibernate.HibernateException; | ||
| import org.hibernate.Internal; | ||
|
|
@@ -349,10 +351,10 @@ public SingleTableEntityPersister( | |
| ); | ||
|
|
||
| // SUBCLASSES | ||
| final List<Subclass> subclasses = persistentClass.getSubclasses(); | ||
| final List<Subclass> subclasses = persistentClass.getSubclasses().stream().sorted(Comparator.comparing(PersistentClass::getEntityName)).collect(Collectors.toList()); | ||
| for ( int k = 0; k < subclasses.size(); k++ ) { | ||
| Subclass subclass = subclasses.get( k ); | ||
| subclassClosure[k] = subclass.getEntityName(); | ||
| subclassClosure[k+1] = subclass.getEntityName(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This off by one error was accidentally introduced in commit a7da407 during a refactor from a foreach loop to a for loop. |
||
| Object subclassDiscriminatorValue = DiscriminatorHelper.getDiscriminatorValue( subclass ); | ||
| addSubclassByDiscriminatorValue( | ||
| subclassesByDiscriminatorValueLocal, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,13 @@ | |
|
|
||
| import java.util.function.Function; | ||
|
|
||
| import org.hibernate.metamodel.mapping.DiscriminatorMapping; | ||
| import org.hibernate.metamodel.mapping.JdbcMapping; | ||
| import org.hibernate.metamodel.mapping.SelectableMapping; | ||
| import org.hibernate.metamodel.mapping.SelectablePath; | ||
| import org.hibernate.sql.ast.tree.expression.ColumnReference; | ||
| import org.hibernate.sql.ast.tree.expression.Expression; | ||
| import org.hibernate.sql.ast.tree.expression.NestedColumnReference; | ||
| import org.hibernate.sql.ast.tree.from.EmbeddableFunctionTableReference; | ||
| import org.hibernate.sql.ast.tree.from.TableReference; | ||
| import org.hibernate.sql.results.graph.FetchParent; | ||
| import org.hibernate.type.NullType; | ||
|
|
@@ -90,7 +90,10 @@ static ColumnReferenceKey createColumnReferenceKey(String tableExpression, Selec | |
| static ColumnReferenceKey createColumnReferenceKey(TableReference tableReference, SelectableMapping selectable) { | ||
| assert tableReference.containsAffectedTableName( selectable.getContainingTableExpression() ) | ||
| : String.format( ROOT, "Expecting tables to match between TableReference (%s) and SelectableMapping (%s)", tableReference.getTableId(), selectable.getContainingTableExpression() ); | ||
| return createColumnReferenceKey( tableReference, selectable.getSelectablePath(), selectable.getJdbcMapping() ); | ||
| final JdbcMapping jdbcMapping = (selectable instanceof DiscriminatorMapping) ? | ||
| ((DiscriminatorMapping)selectable).getUnderlyingJdbcMapping() : | ||
| selectable.getJdbcMapping(); | ||
| return createColumnReferenceKey( tableReference, selectable.getSelectablePath(), jdbcMapping ); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes the discriminator case by using the underlying JDBC type as part of the key to look up the discriminator property in the |
||
| } | ||
|
|
||
| default Expression resolveSqlExpression(TableReference tableReference, SelectableMapping selectableMapping) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The subclasses need to be ordered by the entity name to match the TreeMap with entity name keys used for
AbstractEntityPersister.subclassMappingTypes. Otherwise the column orders can get switched up incorrectly and return the wrong values.