org.springframework.transaction.CannotCreateTransactionException

Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection

Samebug tips2

It's possible you're trying to write to a connection that's already closed. Another cause for this is that you closed the socket with unread data in the socket receive buffer.

This might be caused by unmatching versions of SSL. Java starts normally with SSLv2 and your server might not be able to negotiate. You have to force Java to use SSLv3. See this comment: https://goo.gl/hx0YB3

Don't give up yet. Our experts can help. Paste your full stack trace to get a solution.

Solutions on the web436

  • Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
  • Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
  • via Stack Overflow by Asoub
    , 1 year ago
    Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
  • Stack trace

    • org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:431)[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)[spring-tx-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)[spring-tx-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)[spring-batch-infrastructure-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)[spring-batch-infrastructure-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)[spring-batch-infrastructure-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)[spring-core-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:362)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:590)[spring-batch-core-3.0.4.RELEASE.jar:3.0.4.RELEASE] Caused by: javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1771)[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:64)[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:170)[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)[spring-orm-4.2.3.RELEASE.jar:4.2.3.RELEASE] ... 21 more Caused by: org.hibernate.exception.JDBCConnectionException: Could not open connection at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1435)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:61)[hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] ... 23 more Caused by: org.postgresql.util.PSQLException: La tentative de connexion a échoué. (Note: "The connection attempt failed" in english) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:225)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:136)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.Driver.makeConnection(Driver.java:393)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.Driver.connect(Driver.java:267)[postgresql-9.2-1002.jdbc4.jar:na] at java.sql.DriverManager.getConnection(DriverManager.java:582)[na:1.6.0_45] at java.sql.DriverManager.getConnection(DriverManager.java:154)[na:1.6.0_45] at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:155)[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120)[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228)[hibernate-core-4.3.5.Final.jar:4.3.5.Final] ... 28 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168)[na:1.6.0_45] at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:71)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:269)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:376)[postgresql-9.2-1002.jdbc4.jar:na] at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:173)[postgresql-9.2-1002.jdbc4.jar:na] ... 45 more

    Write tip

    You have a different solution? A short tip here would help you and many other users who saw this issue last week.

    Users with the same issue

    Unknown user
    2 times, 1 year ago
    Unknown user
    Once, 11 months ago
    Unknown user
    Once, 1 year ago
    Unknown user
    Once, 1 year ago
    Unknown user
    Once, 1 year ago
    287 more bugmates