Error advancing (next) ResultSet position + Hibernate v6

Hello Developers,

I recently upgraded hibernate to v6.1.6 from v5.4.33.

We have a table A and table B which is having one to many relation.
Also, the application is a legacy one so we are still using XML configuration and hbm.xml file.

My system.hbm.xml looks like this for these two tables

<class name="entity.TableA" table="table_a">
    <id name="id">
      <generator class="uuid"/>
    <property name="CreatedDate" column="created_date"/>
    <property name="Name" column="name"/>
    <list name="Options" inverse="true" cascade="all-delete-orphan">
      <key column="value"/>
      <index column="seq_num"/>
      <one-to-many class="entity.TableB"/>
  <class name="entity.TableB" table="table_b">
    <id name="id">
      <generator class="uuid"/>
    <property name="CreatedDate" column="created_date"/>
    <property name="SeqNum" column="seq_num"/>
    <property name="Value" column="value"/>
    <many-to-one name="Field" not-null="true" column="name"/>

And I am trying to run a select query on the table_a like this

String hql = "from TableA"
Query query = session.createQuery(hql);
List found = query.list();

which is throwing this error.

Exception in thread "main" jakarta.persistence.PersistenceException: Converting `org.hibernate.sql.exec.ExecutionException` to JPA `PersistenceException` : A problem occurred in the SQL executor : Error advancing (next) ResultSet position
	at org.hibernate.internal.ExceptionConverterImpl.convert(
	at org.hibernate.query.spi.AbstractSelectionQuery.list(
	at org.hibernate.query.sqm.internal.QuerySqmImpl.list(
	at HibernateUtil.query(
	at HibernateUtil.findFields(
	at HibernateImpl.main(
Caused by: org.hibernate.sql.exec.ExecutionException: A problem occurred in the SQL executor : Error advancing (next) ResultSet position
	at org.hibernate.sql.results.jdbc.internal.JdbcValuesResultSetImpl.makeExecutionException(
	at org.hibernate.sql.results.jdbc.internal.JdbcValuesResultSetImpl.advanceNext(
	at org.hibernate.sql.results.jdbc.internal.JdbcValuesResultSetImpl.processNext(
	at org.hibernate.sql.results.spi.ListResultsConsumer.consume(
	at org.hibernate.sql.results.spi.ListResultsConsumer.consume(
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(
	at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(
	at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(
	at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(
	at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(
	at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(
	at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(
	at org.hibernate.query.spi.AbstractSelectionQuery.list(
	... 4 more
Caused by: org.hibernate.exception.GenericJDBCException: Error advancing (next) ResultSet position
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(
	... 20 more
Caused by: java.sql.SQLException: Closed Resultset: next

I need to make it working with hibernate v6.1.6.Final. Please guide me in resolving this, or if I am missing any configuration or something.
NOTE: This code works with Hibernate v5.6.14.Final without any error.

Can you check what SQL is sent to the database since it is an SQLException?

@mkomko it run three queries

Hibernate: select,m1_0.created_date, from table_a m1_0
Hibernate: select,o1_0.seq_num,o1_0.created_date,o1_0.value from table_b o1_0
Hibernate: select,o1_0.seq_num,o1_0.created_date,o1_0.value from table_b o1_0

Hi @ankit_agrahari,

can you provide a simple test that reproduce your issue? this would be really helpful


@dreab8 You can refer to this sample project Hibernatev6, which will throw the error if the hibernate version is 6.1.6. But works if we change the version to 5.6.14 in pom.xml.

You can add the DB details in the file present under the resource dir.

thanks @ankit_agrahari , I’m going to give a look at it!

1 Like

Hi @ankit_agrahari , trying your test but I cannot face any issue, probably because it does not populate the database at all and so it just executes a from MetadataField f query on an empty db.

Hi @dreab8,

Thanks for trying out.

Yes, If the data is not present, it would work without any error, but if the table has some data, then it it giving that error.

Hi @ankit_agrahari ,

can you please open a Jira ?


FYI the issue is triggered by the iteration of the collection inside the setOptions(List<MetadataOption> options) method that is by the way a bad practice when you are using a property-based access strategy.

So at the moment you have few options, remove the iteration for the setOptions(List<MetadataOption> options) method or change Hibernate access strategy to field-based or enclose your query inside a transaction.

Thanks @dreab8
I have raised one issue HHH-16120


Thanks @ankit_agrahari !

I’m going to work on it.


1 Like