org.hibernate.engine.jdbc.internal.JdbcServicesImpl - HHH000342: Could not obtain connection to query metadata : This ResultSet is closed


#1

I am getting the below exception when try to launch my maven project (GWT code) ,

INFO   org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/database_name]
INFO  org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000046: Connection properties: {user=postgres, password=postgres, autocommit=false}

WARN  org.hibernate.engine.jdbc.internal.JdbcServicesImpl - HHH000342: Could not obtain connection to query metadata : This ResultSet is closed.

INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
INFO  org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000422: Disabling contextual LOB creation as connection was null
INFO  org.hibernate.engine.transaction.internal.TransactionFactoryInitiator - HHH000399: Using default transaction strategy (direct JDBC transactions)
INFO  org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO  org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 4.3.1.Final
WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 55000
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - This ResultSet is closed.

Not able to identify why I am getting this exception. In few searches I found results related to correcting hibernate properties, but my hibernate properties are fine as I am able to connect to other databases in remote machines with my same code, but not my database in localhost.

Note: I am also able query my postgresql database using PGAdmin tool and tried restarting postgresql service, eclipse and finally my system. Nothing worked. Also I am able to connect to my local DB from the same piece of Hibernate code from gradle projects . Please help!

The exception I am getting is from maven project.Also I am able to connect to my local DB from the same piece of Hibernate code from gradle projects .As I explored in debug mode I have found that in ‘org.hibernate.engine.jdbc.internal.JdbcServicesImpl’ , in the method ‘configure’ there is a finally block which is doing ‘jdbcConnectionAccess.releaseConnection( connection );’ , this is the place where the SQL exception occurs ‘The ResulSet is closed’ and caught in catch block and printed as

WARN org.hibernate.engine.jdbc.internal.JdbcServicesImpl - HHH000342: Could not obtain connection to query metadata : This ResultSet is closed.
which seems to be like trying to close the jdbc connection which is already closed. But why it is already closed is what I am not able to understand

My Hibernate properties:

hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.password=encrypted_password
hibernate.connection.url=jdbc:postgresql://localhost:5432/database_name
hibernate.connection.username=postgres
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.current_session_context_class=thread
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.connection.autocommit=false
hibernate.jdbc.use_get_generated_keys=true

After hibenate properties are loaded ,

 ServiceRegistry serviceRegistry = (new ServiceRegistryBuilder()).applySettings(configuration.getProperties())
                .buildServiceRegistry();
        this.sessionFactory = configuration.buildSessionFactory(serviceRegistry);

Here buildSessionFactory() will execute the hibernate code where the exception occurs


#2

Add a break point in the close method of the JDBC Connection and see when and who calls close.

Also, try using a proper connection pool like c3p0 or Hikari. Currently, you are using the default DriverManagerConnectionProvider which is not recommanded for production envs, as suggested by a WARN message in your log.


#3

Hi vlad,

Thank you for the reply,
May I know the package name of JDBC Connection which you have mentioned in your comment?

Actually the project uses c3p0 ,

hibernate-c3p0
4.2.1.Final

This is the maven dependency added in pom.xml.

In Web-INF/lib
I see two jars of c3p0
c3p0-0.9.5.jar and
c3p0-0.9.1.jar


#4

The C3P0 Connection Proxy then. Or the one provider by your Driver.


#5

Hi Vlad,

Finally today I have resolved this issue!
The problem was with the version of the postgresql installed in my local machine.
It was v10.0.And the dependency postgres jar downloaded by pom.xml was 9.1.

Today I have uninstalled it completely and installed v9.6 and I didn’t get this exception.
It worked.
Thank You. :slight_smile: