이야기박스

Spring JPA. Batch Insert 에러 본문

Programming Language/Spring

Spring JPA. Batch Insert 에러

박스님 2019. 3. 28. 11:56
반응형
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();

해당 구문을 추가하니 에러가 해결.

반응형