-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-18629 Fix inconsistent column alias generated while result class is used for placeholder #8971
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
Conversation
|
Could someone review? |
hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java
Outdated
Show resolved
Hide resolved
wrong fileid’s alias fileid1_0_0_ is used instead of fileid1_0_1_ while transforming ResultSet to Book. ``` Column "fileid1_0_0_" not found [42122-224] org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "fileid1_0_0_" not found [42122-224] at org.h2.message.DbException.getJdbcSQLException(DbException.java:514) at org.h2.message.DbException.getJdbcSQLException(DbException.java:489) at org.h2.message.DbException.get(DbException.java:223) at org.h2.message.DbException.get(DbException.java:199) at org.h2.jdbc.JdbcResultSet.getColumnIndex(JdbcResultSet.java:3492) at org.h2.jdbc.JdbcResultSet.findColumn(JdbcResultSet.java:178) at org.hibernate.sql.results.jdbc.internal.AbstractResultSetAccess.resolveColumnPosition(AbstractResultSetAccess.java:63) ```
…is used for placeholder
|
|
| 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 ); |
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.
I think it might be better to remove this else-if branch and not alter the resultSetMapping in NativeQueryImpl#addResultTypeClass, but instead store the result class to materialize a fresh ResultSetMapping based on that when needed instead.
Supporting an empty string here and adding a remove method in ResultSetMapping all look like code smells to me. There is also some code duplication and inconsistency it seems when comparing this method to the NativeQueryImpl(org.hibernate.query.sql.spi.NamedNativeQueryMemento<?>, java.lang.Class<R>, org.hibernate.engine.spi.SharedSessionContractImplementor) constructor.
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.
Supporting an empty string here and adding a remove method in ResultSetMapping all look like code smells to me.
I agree, but I'm not familiar with ResultSetMapping, I tried and failed, feel free to close this PR and propose new PR.
|
Close it in favor of #9075 |
wrong fileid’s alias fileid1_0_0_ is used instead of fileid1_0_1_ while transforming ResultSet to Book.
[Please describe here what your change is about]
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-18629