我有一个连接到MS SQL Server的Spring启动应用程序。 HikariCP用于DS。在测试环境中,SQL Server DB每晚都会因某种原因重新启动(我不知道)。重新启动数据库直到我重新启动应用程序,我看到以下异常。我希望在不重新启动应用程序的情况下重置连接。感谢任何帮助以避免此错误
javax.persistence.PersistenceException: org.hibernate.TransactionException: Already have an associated managed connection
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1771) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:64) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.enlistInCurrentTransaction(ExtendedEntityManagerCreator.java:398) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:376) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:327) ~[spring-orm-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at com.sun.proxy.$Proxy119.joinTransaction(Unknown Source) ~[na:na]
at org.apache.camel.component.jpa.JpaConsumer$1.doInTransaction(JpaConsumer.java:97) ~[camel-jpa-2.15.2.1.jar!/:2.15.2..1]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.apache.camel.component.jpa.JpaConsumer.poll(JpaConsumer.java:94) ~[camel-jpa-2.15.2..1.jar!/:2.15.2..1]
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174) [camel-core-2.15.2.jar!/:2.15.2]
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101) [camel-core-2.15.2.jar!/:2.15.2]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_05]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_05]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_05]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_05]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_05]
Caused by: org.hibernate.TransactionException: Already have an associated managed connection
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:65) ~[hibernate-core-4.3.10.Final.jar!/:4.3.10.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:162) ~[hibernate-core-4.3.10.Final.jar!/:4.3.10.Final]
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1471) ~[hibernate-core-4.3.10.Final.jar!/:4.3.10.Final]
at org.hibernate.jpa.internal.TransactionImpl.begin(TransactionImpl.java:61) ~[hibernate-entitymanager-4.3.10.Final.jar!/:4.3.10.Final]
... 16 common frames omitted