이야기박스
Spring JPA. Batch Insert 에러 본문
반응형
EntityManager entityManager = entityManagerFactory.createEntityManager();
EntityTransaction transaction = entityManager.getTransaction();
을 통하여 transaction 생성 후,
transaction.begin();
entityManager.persist(data)
transaction.commit();
이러한 구조로 했었는데 에러가 발생하였다.
에러 메세지
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert([SQLExceptionTypeDelegate.java:48)](SQLExceptionTypeDelegate.java:48))
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert([StandardSQLExceptionConverter.java:42)](StandardSQLExceptionConverter.java:42))
at [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)](org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111))
at [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)](org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97))
at [org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:109)](org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:109))
at [org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)](org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136))
at [org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:254)](org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:254))
at [org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:262)](org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:262))
at [org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:214)](org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:214))
at [org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:56)](org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:56))
at [com.netmarble.big.bigsession.handler.BigSessionDbHandlerImpl.insertSessionDbResult(BigSessionDbHandlerImpl.java:158)](com.netmarble.big.bigsession.handler.BigSessionDbHandlerImpl.insertSessionDbResult(BigSessionDbHandlerImpl.java:158))
at [com.netmarble.big.bigsession.scheduler.BigSessionScheduler.lambda$scheduleTaskWithCronExpression$0(BigSessionScheduler.java:40)](com.netmarble.big.bigsession.scheduler.BigSessionScheduler.lambda$scheduleTaskWithCronExpression$0(BigSessionScheduler.java:40))
at [java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)](java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149))
at [java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)](java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624))
at [java.lang.Thread.run(Thread.java:748)](java.lang.Thread.run(Thread.java:748))
Caused by: [java.sql.SQLTransientConnectionException:](java.sql.SQLTransientConnectionException:) cpdevSessionDbPool - Connection is not available, request timed out after 2002ms.
at [com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:676)](com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:676))
at [com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:190)](com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:190))
at [com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:155)](com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:155))
at [com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128)](com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:128))
at [org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)](org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122))
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection([NonContextualJdbcConnectionAccess.java:35)](NonContextualJdbcConnectionAccess.java:35))
at [org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)](org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106))
... 10 more
Exception in thread "pool-3-thread-2" [java.lang.IllegalStateException:](java.lang.IllegalStateException:) Transaction not successfully started
at [org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:63)](org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:63))
at [com.netmarble.big.bigsession.handler.BigSessionDbHandlerImpl.insertSessionDbResult(BigSessionDbHandlerImpl.java:171)](com.netmarble.big.bigsession.handler.BigSessionDbHandlerImpl.insertSessionDbResult(BigSessionDbHandlerImpl.java:171))
at [com.netmarble.big.bigsession.scheduler.BigSessionScheduler.lambda$scheduleTaskWithCronExpression$0(BigSessionScheduler.java:40)](com.netmarble.big.bigsession.scheduler.BigSessionScheduler.lambda$scheduleTaskWithCronExpression$0(BigSessionScheduler.java:40))
at [java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)](java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149))
at [java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)](java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624))
at [java.lang.Thread.run(Thread.java:748)](java.lang.Thread.run(Thread.java:748))
원인은 entityManager를 닫아주지 않아서이다.
entityManager.close();
해당 구문을 추가하니 에러가 해결.
반응형
'Programming Language > Spring' 카테고리의 다른 글
Spring. SpringJDBC - ibatis 환경에서 Transaction 진행 (1) | 2019.10.18 |
---|---|
Spring - Filter (0) | 2019.08.13 |
Chapter 8. 스프링이란 무엇인가? (0) | 2019.03.22 |
Chapter 7. 스프링 핵심 기술의 응용 (0) | 2019.03.21 |
Chapter 6. AOP(3) 포인트 컷과 트랜잭션 (0) | 2019.02.08 |