<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=youngm" rel="nofollow">Mike Youngstrom</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8800?redirect=false" rel="nofollow">SPR-8800</a></strong> and commented</p>
<p dir="auto">Using Spring 3.1 rc1 I get a new error when using hibernate with JTA multiple times in the same thread.  What appears to be happening is the HibernateJpaDialect is adding the Hibernate SessionFactory to the transactional resources for some reason.  It assumes that when the transaction commits  EntityManagerFactoryUtils.cleanupTransaction() will be called.  However it doesn't in my situation.</p>
<p dir="auto">I've included a maven test case.  To duplicate simply run mvn test.  If you change the version of spring to 3.0.6.RELEASE then the test passes.</p>
<p dir="auto">Below is the exception I get:</p>
<p dir="auto">java.lang.IllegalStateException: Already value [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])] for key [org.hibernate.internal.SessionFactoryImpl@1d7b222] bound to thread [main]<br>
at org.springframework.transaction.support.TransactionSynchronizationManager.bindResource(TransactionSynchronizationManager.java:180)<br>
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.prepareTransaction(HibernateJpaDialect.java:98)<br>
at org.springframework.orm.jpa.EntityManagerFactoryUtils.prepareTransaction(EntityManagerFactoryUtils.java:230)<br>
at org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetTransactionalEntityManager(EntityManagerFactoryUtils.java:207)<br>
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:211)<br>
at $Proxy16.getDelegate(Unknown Source)<br>
at test.JpaTest$2.doInTransaction(JpaTest.java:32)<br>
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)<br>
at test.JpaTest.test(JpaTest.java:30)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:597)<br>
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)<br>
at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:169)<br>
at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:158)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:597)<br>
at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:181)<br>
at org.testng.internal.Invoker.invokeMethod(Invoker.java:684)<br>
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)<br>
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)<br>
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)<br>
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)<br>
at org.testng.TestRunner.privateRun(TestRunner.java:753)<br>
at org.testng.TestRunner.run(TestRunner.java:613)<br>
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)<br>
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)<br>
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)<br>
at org.testng.SuiteRunner.run(SuiteRunner.java:240)<br>
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)<br>
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)<br>
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)<br>
at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)<br>
at org.testng.TestNG.run(TestNG.java:974)<br>
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)<br>
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)<br>
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)</p>
<hr>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/19015/test-jpa-binding.zip" rel="nofollow">test-jpa-binding.zip</a> (<em>2.89 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398115022" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13414" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13414/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13414">#13414</a> Jpa transaction manager transaction suspension ignores dialect resources</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=paulm" rel="nofollow">Paul Middelkoop</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8651?redirect=false" rel="nofollow">SPR-8651</a></strong> and commented</p>
<p dir="auto">Tested on nightly build of August 29th 2011:</p>
<p dir="auto">public interface MyRepository {<br>
}</p>
<p dir="auto"><code class="notranslate">@Component</code><br>
public class MyRepositoryImpl implements MyRepository {<br>
<code class="notranslate">@Scheduled</code>(fixedDelay = 5)<br>
public void initCache() {}<br>
}</p>
<p dir="auto">This works. But when I change from <code class="notranslate">@Component</code> to <code class="notranslate">@Repository</code> I get this exception:</p>
<p dir="auto">java.lang.IllegalArgumentException: object is not an instance of declaring class<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:597)<br>
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)<br>
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)<br>
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)<br>
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)<br>
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)<br>
at java.util.concurrent.FutureTask.run(FutureTask.java:138)<br>
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)<br>
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)<br>
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)<br>
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)<br>
at java.lang.Thread.run(Thread.java:662)</p>
<p dir="auto">Adding the <code class="notranslate">@Scheduled</code> method to the interface doesn't help also.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M2</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398115736" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13514" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13514/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13514">#13514</a> <code class="notranslate">@Scheduled</code> does not work in classes annotated with <code class="notranslate">@Cacheable</code> (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/d4123d06379fadc0b05043f5ab5a1a2cb264314b/hovercard" href="https://github.com/spring-projects/spring-framework/commit/d4123d06379fadc0b05043f5ab5a1a2cb264314b"><tt>d4123d0</tt></a></p>
<p dir="auto">2 votes, 3 watchers</p>