Operation not allowed after ResultSet closed during an update operation in hibernate 5.4.23

Hi,
i am using hibernate 5.4.23 version ,mysql database 8.0.11 connector jar and hikaricp connection pool.
sometimes during update getting below exception from hibernate.

HHH000327: Error performing load command
** org.hibernate.exception.GenericJDBCException: could not load an entity: [org.vn.cc.entities.client.Contact#346745]**
** at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)**
** at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)**
** at org.hibernate.loader.Loader.loadEntity(Loader.java:2426)**
** at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:74)**
** at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:63)**
** at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:4394)**
** at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4384)**
** at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:569)**
** at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:537)**
** at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:208)**
** at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:332)**
** at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:108)**
** at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:74)**
** at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:113)**
** at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1186)**
** at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1175)**
** at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:193)**
** at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2786)**
** at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2767)**
** at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2723)**
** at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2767)**
** at org.hibernate.internal.SessionImpl.get(SessionImpl.java:988)**
** at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:306)**
** at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:172)**
** at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:70)**
** at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)**
** at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:793)**
** at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:780)**
** at code.db.jpa.mysql.MySQLem.Update(MySQLem.java:222)**
** at org.vn.cc.server.db.DB.Update(DB.java:164)**


Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
** at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)**
** at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)**
** at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87)**
** at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61)**
** at com.mysql.cj.jdbc.result.ResultSetImpl.checkClosed(ResultSetImpl.java:459)**
** at com.mysql.cj.jdbc.result.ResultSetImpl.next(ResultSetImpl.java:1688)**
** at com.zaxxer.hikari.pool.HikariProxyResultSet.next(HikariProxyResultSet.java)**
** at org.hibernate.loader.Loader.getRowsFromResultSet(Loader.java:1035)**
** at org.hibernate.loader.Loader.processResultSet(Loader.java:990)**
** at org.hibernate.loader.Loader.doQuery(Loader.java:959)**
** at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349)**
** at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:319)**
** at org.hibernate.loader.Loader.loadEntity(Loader.java:2422)**

Any idea why hibernate throws this exception and what i could do to solve this issue ?

Thank You!!

Looks like you might be sharing the Session/EntityManager between different threads.

Hi,
we are using hibernate jpa resource-local entity manager in application.do we have to create multiple entitymanager to use in multiple threads…?
we ve configured hikaricp connection pool,could you please explain when connections are exactly used/returned from connectionpool using entitymanager in hibernate.
Thank you!!!

Yes, every thread has to create a new entity manager. In fact, it would be best to have a dedicated entity manager per transaction. When a connection is returned/closed depends on various things. Transaction manager, configuration etc. but that shouldn’t be an issue. Just make sure you are not sharing Session/EntityManager instances.