Skip to content

Conversation

@quaff
Copy link
Contributor

@quaff quaff commented Sep 18, 2024

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)

[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

@quaff quaff changed the title HHH-18629 add test for issue HHH-18629 Fix inconsistent column alias generated while result class is used for placeholder Sep 18, 2024
@quaff
Copy link
Contributor Author

quaff commented Sep 27, 2024

Could someone review?

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)
```
@quaff
Copy link
Contributor Author

quaff commented Sep 27, 2024

EntityWithCollectionReloadCacheTest failed with Sybase, I don't think it's caused by this PR.

java.lang.IllegalArgumentException: Expecting 8 byte values to construct a long
	at org.hibernate.internal.util.BytesHelper.asLong(BytesHelper.java:117)
	at org.hibernate.type.descriptor.java.UUIDJavaType$ToBytesTransformer.parse(UUIDJavaType.java:160)
	at org.hibernate.type.descriptor.java.UUIDJavaType.wrap(UUIDJavaType.java:87)
	at org.hibernate.type.descriptor.java.UUIDJavaType.wrap(UUIDJavaType.java:23)
	at org.hibernate.type.descriptor.jdbc.VarbinaryJdbcType$2.doExtract(VarbinaryJdbcType.java:113)
	at org.hibernate.type.descriptor.jdbc.BasicExtractor.extract(BasicExtractor.java:42)
	at org.hibernate.sql.results.jdbc.internal.JdbcValuesResultSetImpl.getCurrentRowValue(JdbcValuesResultSetImpl.java:385)
	at org.hibernate.sql.results.internal.RowProcessingStateStandardImpl.getJdbcValue(RowProcessingStateStandardImpl.java:150)
	at org.hibernate.sql.results.graph.basic.BasicResultAssembler.extractRawValue(BasicResultAssembler.java:52)
	at org.hibernate.sql.results.graph.basic.BasicResultAssembler.assemble(BasicResultAssembler.java:58)
	at org.hibernate.sql.results.graph.collection.internal.AbstractImmediateCollectionInitializer.resolveCollectionContentKey(AbstractImmediateCollectionInitializer.java:166)
	at org.hibernate.sql.results.graph.collection.internal.AbstractImmediateCollectionInitializer.resolveKey(AbstractImmediateCollectionInitializer.java:121)
	at org.hibernate.sql.results.graph.collection.internal.AbstractImmediateCollectionInitializer.resolveKey(AbstractImmediateCollectionInitializer.java:40)
	at org.hibernate.sql.results.graph.Initializer.resolveKey(Initializer.java:99)
	at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKeySubInitializers(EntityInitializerImpl.java:705)
	at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:612)
	at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:463)
	at org.hibernate.sql.results.graph.entity.internal.EntityInitializerImpl.resolveKey(EntityInitializerImpl.java:93)
	at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:228)
	at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:134)
	at org.hibernate.sql.results.spi.ListResultsConsumer.read(ListResultsConsumer.java:247)
	at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:199)
	at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:222)
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:100)
	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.executeQuery(JdbcSelectExecutor.java:64)
	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:138)
	at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$1(ConcreteSqmSelectQueryPlan.java:150)
	at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:440)
	at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:360)
	at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:374)
	at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:141)
	at org.hibernate.query.Query.getResultList(Query.java:118)
	at org.hibernate.orm.test.querycache.EntityWithCollectionReloadCacheTest.lambda$test$1(EntityWithCollectionReloadCacheTest.java:63)
	at org.hibernate.testing.orm.transaction.TransactionUtil.wrapInTransaction(TransactionUtil.java:47)
	at org.hibernate.testing.orm.transaction.TransactionUtil.inTransaction(TransactionUtil.java:22)
	at org.hibernate.testing.orm.junit.SessionFactoryExtension$SessionFactoryScopeImpl.inTransaction(SessionFactoryExtension.java:371)
	at org.hibernate.testing.orm.junit.SessionFactoryExtension$SessionFactoryScopeImpl.inTransaction(SessionFactoryExtension.java:348)
	at org.hibernate.orm.test.querycache.EntityWithCollectionReloadCacheTest.test(EntityWithCollectionReloadCacheTest.java:53)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

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 );
Copy link
Member

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.

Copy link
Contributor Author

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.

@quaff
Copy link
Contributor Author

quaff commented Oct 10, 2024

Close it in favor of #9075

@quaff quaff closed this Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants