Envers: java.sql.SQLException: Invalid state, the ResultSet object is closed

Hello :slight_smile:

I have a problem with Hibernate Envers, we use Hibernate v.5 and Hibernate Envers in our persistence bundles within a large set of OSGi bundles that cater to an upstream platform. Our Hibernate stuff works generally fine, but Envers is giving me quite a headache.

Here’s my code, or actually three versions of what I’ve tried, and all of them throw the exception during the same call to getResultList:

/**
 * the very first try
 */
@SuppressWarnings("unchecked")
public List<ISomeKindOfPerson> searchDeletedPeople(IProcessContext processContext, String firstName, String lastName, PartialDate birthDate) 
throws OurCheckedWhateverWentWrongException, UpstreamCheckedWeMessedUpOurProvidersException, NonUniqueResultException, NoResultException {
	final Map<UUID, PersonSearchRecord> uniquePersonSearchRecords = new HashMap<>();
	final List<ISomeKindOfPerson> auditedPeople = new ArrayList<>();
	
	if (StringUtils.isBlank(firstName) && StringUtils.isBlank(lastName) && birthDate == null)
		return Collections.emptyList();
	
	try (SessionImplementor em = Persistence.createEM(processContext)) {
		final AuditReader reader = AuditReaderFactory.get(em);
		
		final AuditQuery personSearchRecordQuery = reader.createQuery().forRevisionsOfEntity(PersonSearchRecord.class, true, true);
		personSearchRecordQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
		
		if (StringUtils.isNotBlank(firstName)) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.FIRST).ilike(firstName, MatchMode.ANYWHERE));
		}
		if (StringUtils.isNotBlank(lastName)) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.LAST).ilike(lastName, MatchMode.ANYWHERE));
		}
		if (birthDate != null) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.BIRTHDATE).eq(new ProPartialDate(birthDate)));
		}
		
		final List<PersonSearchRecord> results = personSearchRecordQuery.getResultList(); // luckily this works without any explicit casting in my limited click-testing so far
		for (final PersonSearchRecord personSearchRecord : results) {
			if (!uniquePersonSearchRecords.containsKey(personSearchRecord.getIdent())) {
				uniquePersonSearchRecords.put(personSearchRecord.getUuid(), personSearchRecord);
			}
		}

		for (final Map.Entry<UUID, PersonSearchRecord> personSearchRecord : uniquePersonSearchRecords.entrySet()) {
			final AuditQuery personQuery = reader.createQuery().forRevisionsOfEntity(Person.class, true, true);
			personQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
			personQuery.add(AuditEntity.id().eq(personSearchRecord.getValue().getPersonId()));
			
			final List<Person> queryResults = personQuery.getResultList(); // <------- throws java.sql.SQLException: Invalid state, the ResultSet object is closed.

			if (CollectionUtils.isNotEmpty(queryResults))
				auditedPeople.addAll(queryResults);
		}
	} catch (final HibernateException e) {
		throw new OurCheckedWhateverWentWrongException(e);
	}
	return auditedPeople;
}
/**
 * the second try
 */
@SuppressWarnings("unchecked")
public List<ISomeKindOfPerson> searchDeletedPeople(IProcessContext processContext, String firstName, String lastName, PartialDate birthDate) 
throws OurCheckedWhateverWentWrongException, UpstreamCheckedWeMessedUpOurProvidersException, NonUniqueResultException, NoResultException {
	final Map<UUID, PersonSearchRecord> uniquePersonSearchRecords = new HashMap<>();
	final List<ISomeKindOfPerson> auditedPeople = new ArrayList<>();
	
	if (StringUtils.isBlank(firstName) && StringUtils.isBlank(lastName) && birthDate == null)
		return Collections.emptyList();
	
	try (SessionImplementor em = Persistence.createEM(processContext)) {
		final AuditReader personSearchRecordReader = AuditReaderFactory.get(em);
		
		final AuditQuery personSearchRecordQuery = personSearchRecordReader.createQuery().forRevisionsOfEntity(PersonSearchRecord.class, true, true);
		personSearchRecordQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
		
		if (StringUtils.isNotBlank(firstName)) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.FIRST).ilike(firstName, MatchMode.ANYWHERE));
		}
		if (StringUtils.isNotBlank(lastName)) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.LAST).ilike(lastName, MatchMode.ANYWHERE));
		}
		if (birthDate != null) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.BIRTHDATE).eq(new ProPartialDate(birthDate)));
		}
		
		final List<PersonSearchRecord> results = personSearchRecordQuery.getResultList(); // luckily this works without any explicit casting in my limited click-testing so far
		for (final PersonSearchRecord personSearchRecord : results) {
			if (!uniquePersonSearchRecords.containsKey(personSearchRecord.getIdent())) {
				uniquePersonSearchRecords.put(personSearchRecord.getUuid(), personSearchRecord);
			}
		}
	} catch (final HibernateException e) {
		throw new OurCheckedWhateverWentWrongException(e);
	}
	
	try (SessionImplementor em = Persistence.createEM(processContext)) {
		final AuditReader personReader = AuditReaderFactory.get(em);
		for (final Map.Entry<UUID, PersonSearchRecord> personSearchRecord : uniquePersonSearchRecords.entrySet()) {
			final AuditQuery personQuery = personReader.createQuery().forRevisionsOfEntity(Person.class, true, true);
			personQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
			personQuery.add(AuditEntity.id().eq(personSearchRecord.getValue().getPersonId()));
			
			final List<Person> queryResults = personQuery.getResultList(); // <------- throws java.sql.SQLException: Invalid state, the ResultSet object is closed.

			if (CollectionUtils.isNotEmpty(queryResults))
				auditedPeople.addAll(queryResults);
		}
	} catch (final HibernateException e) {
		throw new OurCheckedWhateverWentWrongException(e);
	}
	return auditedPeople;
}
/**
 * the third try
 */
@SuppressWarnings("unchecked")
public List<ISomeKindOfPerson> searchDeletedPeople(IProcessContext processContext, String firstName, String lastName, PartialDate birthDate) 
throws OurCheckedWhateverWentWrongException, UpstreamCheckedWeMessedUpOurProvidersException, NonUniqueResultException, NoResultException {
	final Map<UUID, PersonSearchRecord> uniquePersonSearchRecords = new HashMap<>();
	final List<ISomeKindOfPerson> auditedPeople = new ArrayList<>();
	
	if (StringUtils.isBlank(firstName) && StringUtils.isBlank(lastName) && birthDate == null)
		return Collections.emptyList();
	
	try (SessionImplementor em = Persistence.createEM(processContext)) {
		final AuditReader personSearchRecordReader = AuditReaderFactory.get(em);
		
		final AuditQuery personSearchRecordQuery = personSearchRecordReader.createQuery().forRevisionsOfEntity(PersonSearchRecord.class, true, true);
		personSearchRecordQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
		
		if (StringUtils.isNotBlank(firstName)) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.FIRST).ilike(firstName, MatchMode.ANYWHERE));
		}
		if (StringUtils.isNotBlank(lastName)) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.LAST).ilike(lastName, MatchMode.ANYWHERE));
		}
		if (birthDate != null) {
			personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.BIRTHDATE).eq(new ProPartialDate(birthDate)));
		}
		
		final List<PersonSearchRecord> results = personSearchRecordQuery.getResultList(); // luckily this works without any explicit casting in my limited click-testing so far
		for (final PersonSearchRecord personSearchRecord : results) {
			if (!uniquePersonSearchRecords.containsKey(personSearchRecord.getIdent())) {
				uniquePersonSearchRecords.put(personSearchRecord.getUuid(), personSearchRecord);
			}
		}
	} catch (final HibernateException e) {
		throw new OurCheckedWhateverWentWrongException(e);
	}
	
	for (final Map.Entry<UUID, PersonSearchRecord> personSearchRecord : uniquePersonSearchRecords.entrySet()) {
		try (SessionImplementor em = Persistence.createEM(processContext)) {
			final AuditReader personReader = AuditReaderFactory.get(em);
			final AuditQuery personQuery = personReader.createQuery().forRevisionsOfEntity(Person.class, true, true);
			personQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
			personQuery.add(AuditEntity.id().eq(personSearchRecord.getValue().getPersonId()));
			
			final List<Person> queryResults = personQuery.getResultList(); // <------- throws java.sql.SQLException: Invalid state, the ResultSet object is closed.

			if (CollectionUtils.isNotEmpty(queryResults))
				auditedPeople.addAll(queryResults);
		} catch (final HibernateException e) {
			throw new OurCheckedWhateverWentWrongException(e);
		}
	}
	return auditedPeople;
}

Any pointers to what I’m doing wrong are very appreciated :slight_smile:

Many thanks in advance for any help

Cheers
Zac

Please share the exact versions you use and the stack trace as well :slight_smile:

Hibernate/Envers version: 5.6.15
Current code/stacktrace below the text.
I need to redact all parts of the stacktrace and code that allow to infer which product I’m working on, therefore it might be a bit weird to read, but my hands are also tied here :frowning:

Hello and sorry for my late reply, I was trying to troubleshoot my issue a bit further. At first, seemingly there were bugs in our hashCode/equals/toString implementations throughout the whole relation-hierarchy.
Now after fixing these issues, my furtherly persisting problem with the ResultSet being closed before access seems to be connected to Envers loading all related collections lazily, since the collection for a person’s names gets accessed by the serializer to use the Person in the frontend, but also all ways of manually initializing it immediately after retrieving the resultList in the same session failed.
So no matter whether I call size() on the collection or try to use Hibernate.initialize(), or even just log each entry in the collection, it fails with a PersistenceException/HibernateException/SQLException refferring to a closed ResultSet. Funnily enough, when I inspect the resultList in eclipse’s debugger, this initializes the list correctly and everything works fine, just that somehow some of the possible automated ways to initialize the names collection all fail.

Here’s my current code:

@SuppressWarnings("unchecked")
	@Override
	public List<ISomeKindOfPerson> searchDeletedPerson(IProcessContext processContext, String firstName, String lastName,
			PartialDate birthDate) throws OurCheckedWhateverWentWrongException, UpstreamCheckedWeMessedUpOurProvidersException, NonUniqueResultException, NoResultException {
		final Map<UUID, Long> uniquePersonSearchRecordIds = new HashMap<>();
		final List<ISomeKindOfPerson> historicalPeople = new ArrayList<>();
		
		if (StringUtils.isBlank(firstName) && StringUtils.isBlank(lastName) && birthDate == null)
			return Collections.emptyList();
		
		try (SessionImplementor em = Persistence.createEM(processContext)) {
			final AuditReader personSearchRecordReader = AuditReaderFactory.get(em);
			final AuditQuery deletedPeopleIdsQuery = personSearchRecordReader.createQuery().forRevisionsOfEntity(Person.class, true, true);
			deletedPeopleIdsQuery.addProjection(AuditEntity.id());
			deletedPeopleIdsQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
			
			final List<Number> deletedPeopleIds = deletedPeopleIdsQuery.getResultList().stream()
					.map(numObj -> (Number) numObj)
					.toList();
			
			final AuditQuery personSearchRecordQuery = personSearchRecordReader.createQuery().forRevisionsOfEntity(PersonSearchRecord.class, true, true);
			personSearchRecordQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
			personSearchRecordQuery.add(AuditEntity.property("pid").in(deletedPeopleIds));
			
			if (StringUtils.isNotBlank(firstName)) {
				personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.VOR).ilike(firstName, MatchMode.ANYWHERE));
			}
			if (StringUtils.isNotBlank(lastName)) {
				personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.NACH).ilike(lastName, MatchMode.ANYWHERE));
			}
			if (birthDate != null) {
				personSearchRecordQuery.add(AuditEntity.property(PersonSearchRecord.COLUMN_NAMES.GEBURTSDATUM).eq(new ProPartialDate(birthDate)));
			}
			
			final List<PersonSearchRecord> deletedPersonSearchRecords = personSearchRecordQuery.getResultList();
			if (CollectionUtils.isEmpty(deletedPersonSearchRecords)) {
				try (PersonSearchRecordDAO personSearchRecordDAO = new PersonSearchRecordDAO(processContext, em)) {
					deletedPersonSearchRecords.addAll(personSearchRecordDAO.findByIds(IUtils.convert(deletedPeopleIds, Long.class)).stream()
							.filter(personSearchRecord -> StringUtils.isNotBlank(firstName) && personSearchRecord.getVor().contains(firstName) 
									|| StringUtils.isNotBlank(lastName) && personSearchRecord.getNach().contains(lastName) 
									|| birthDate != null && birthDate.equals(personSearchRecord.getGeburtsdatum()))
							.toList());
				}
			}
			for (final PersonSearchRecord deletedPersonSearchRecord : deletedPersonSearchRecords) {
				if (!uniquePersonSearchRecordIds.containsKey(deletedPersonSearchRecord.getIdent())) {
					uniquePersonSearchRecordIds.put(deletedPersonSearchRecord.getIdent(), deletedPersonSearchRecord.getPid());
				}
			}
		} catch (final HibernateException e) {
			throw new OurCheckedWhateverWentWrongException(e);
		}
		
		try (SessionImplementor em = Persistence.createEM(processContext)) {
			for (final UUID personSearchRecordUuid : uniquePersonSearchRecordIds.keySet()) {
				final AuditReader personReader = AuditReaderFactory.get(em);
				final AuditQuery personQuery = personReader.createQuery().forRevisionsOfEntity(Person.class, true, true);
				personQuery.add(AuditEntity.revisionType().eq(RevisionType.DEL));
				personQuery.add(AuditEntity.property("ident").eq(personSearchRecordUuid));
				
				final List<Person> deletedPeople = personQuery.getResultList();
				for (Person deletedPerson : deletedPeople) {
					deletedPerson.getNamen().size(); // init because Envers doesn't load eagerly as set in Entities' Annotations
				}
				
				if (CollectionUtils.isNotEmpty(deletedPeople)) {
					historicalPeople.addAll(deletedPeople);
				}
			}
		} catch (final HibernateException e) {
			throw new OurCheckedWhateverWentWrongException(e);
		}
		return historicalPeople;
	}

And here’s the stacktrace:

redacted.redacted.redacted.redacted.SomeException: BEFORE-0003: The method 'redacted([{"name":"Redacted03","lastName":null,"birthDate":null}])' could not be executed.
Caused by javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
Caused by org.hibernate.exception.GenericJDBCException: could not execute query
Caused by java.sql.SQLException: Invalid state, the ResultSet object is closed.
	at redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:249)
	at redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:303)
	at redacted.redacted.redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:47)
	at redacted.redacted.redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:109)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
	at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:97)
	at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:80)
	at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42)
	at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49)
	at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
	at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:48)
	at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:39)
	at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1624)
	at redacted.redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:127)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1594)
	at org.eclipse.jetty.websocket.servlet.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:170)
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:202)
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1594)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:506)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1571)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1378)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:463)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1544)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1300)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at redacted.redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:114)
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:714)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.Server.handle(Server.java:562)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:319)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:530)
	at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:379)
	at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:146)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:412)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:381)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:268)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:138)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:407)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:894)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1038)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1626)
	at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:51)
	at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:35)
	at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.size(CollectionProxy.java:51)
	at redacted.redacted.redacted.redacted.redacted.redacted.redacted.redacted(RedactedDeleteService.java:422)
	at redacted.redacted.redacted.redacted.redacted.redacted.redacted.redacted(RedactedDelete.java:184)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at redacted.redacted.redacted.redacted.redacted.redacted(redacted.java:217)
	... 58 more
Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
	at org.hibernate.loader.Loader.doList(Loader.java:2871)
	at org.hibernate.loader.Loader.doList(Loader.java:2850)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2682)
	at org.hibernate.loader.Loader.list(Loader.java:2677)
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:540)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:218)
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1459)
	at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649)
	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
	... 68 more
Caused by: java.sql.SQLException: Invalid state, the ResultSet object is closed.
	at net.sourceforge.jtds.jdbc.JtdsResultSet.checkOpen(JtdsResultSet.java:302)
	at net.sourceforge.jtds.jdbc.JtdsResultSet.findColumn(JtdsResultSet.java:977)
	at net.sourceforge.jtds.jdbc.JtdsResultSet.getLong(JtdsResultSet.java:1006)
	at com.zaxxer.hikari.pool.HikariProxyResultSet.getLong(HikariProxyResultSet.java)
	at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:63)
	at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
	at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
	at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
	at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243)
	at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:329)
	at org.hibernate.type.ComponentType.hydrate(ComponentType.java:670)
	at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:207)
	at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:273)
	at org.hibernate.loader.hql.QueryLoader.getResultRow(QueryLoader.java:491)
	at org.hibernate.loader.hql.QueryLoader.getResultColumnOrRow(QueryLoader.java:474)
	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:778)
	at org.hibernate.loader.Loader.getRowsFromResultSet(Loader.java:1047)
	at org.hibernate.loader.Loader.processResultSet(Loader.java:998)
	at org.hibernate.loader.Loader.doQuery(Loader.java:967)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:357)
	at org.hibernate.loader.Loader.doList(Loader.java:2868)
	... 77 more

Many thanks for the help and have a good weekend :slight_smile:
Zac

Thanks for sharing this info, but I fear there is not much we can help you with. First of all, you shouldn’t be using the jTDS driver as that is not supported, neither for Sybase nor SQL Server. We just use it for basic testing Sybase testing in our ORM testsuite, but it’s not for production use. This could very well be just a driver bug.
If using the jconn4 driver from SAP if your using Sybase or using the mssql-jdbc driver for SQL Server doesn’t help, we’d need you to provide us a reproducer for this scenario. By looking at the stacktrace, it doesn’t make any sense why the result set would be closed while querying. Maybe an earlier error got swallowed somewhere in the logs?