[hibernate-dev] Temporary session and commit issue with manual flush mode

Steve Ebersole steve at hibernate.org
Mon Feb 20 09:29:10 EST 2012


Well these are the kind of details I was asking about with 
transactionContext()  :)

So transactionContext() is sharing too much of itself at the moment to 
use it this way.  Currently it just shares the entire 
org.hibernate.engine.transaction.spi.TransactionContext from the 
originating Session.  When the "subordinate" Session is closed it is 
closing that shared TransactionContext.  Later when the originating 
Session tries to access it we have problems.

The main question is whether we should change this up in point release. 
 Or just keep it as-is since y'all have a working approach anyway


On Sat 18 Feb 2012 01:27:26 AM CST, Łukasz Antoniak wrote:
> I totally agree with you guys :). However, when I do something like:
>
> if (FlushMode.isManualFlushMode(session.getFlushMode())) {
> Session temporarySession = null;
> try {
> temporarySession = ((Session) 
> session).sessionWithOptions().transactionContext()
> .connectionReleaseMode(ConnectionReleaseMode.AFTER_TRANSACTION)
> .openSession();
> executeInSession(temporarySession);
> temporarySession.flush();
> } finally {
> if (temporarySession != null) {
> temporarySession.close();
> }
> }
> } else {
>
> I receive an exception:
>
> 08:20:40,296 DEBUG SQL:104 - insert into StrTestEntity (id, str) 
> values (null, ?)
> 08:20:40,359 DEBUG SQL:104 - insert into REVINFO (REV, REVTSTMP) 
> values (null, ?)
> 08:20:40,375 DEBUG SQL:104 - insert into StrTestEntity_AUD (REVTYPE, 
> str, id, REV) values (?, ?, ?, ?)
>
> javax.persistence.PersistenceException: 
> org.hibernate.ResourceClosedException: This TransactionCoordinator has 
> been closed
> at 
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1360) 
>
> at 
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1288) 
>
> at 
> org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1370) 
>
> at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:60)
> at 
> org.hibernate.envers.test.integration.flush.ManualFlush.initData(ManualFlush.java:63) 
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
>
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
>
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
>
> at 
> org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:63) 
>
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
>
> at 
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
>
> at 
> org.hibernate.testing.junit4.FailureExpectedHandler.evaluate(FailureExpectedHandler.java:59) 
>
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) 
>
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) 
>
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) 
>
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at 
> org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:43) 
>
> at 
> org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:42) 
>
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at org.junit.runners.Suite.runChild(Suite.java:128)
> at org.junit.runners.Suite.runChild(Suite.java:24)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
> at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94) 
>
> at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192) 
>
> at 
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>
> at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
> Caused by: org.hibernate.ResourceClosedException: This 
> TransactionCoordinator has been closed
> at 
> org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.getTransaction(TransactionCoordinatorImpl.java:186) 
>
> at 
> org.hibernate.internal.SessionImpl.getTransaction(SessionImpl.java:1303)
> at 
> org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1308) 
>
> at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:57)
> ... 40 more
>
> Without explicitly closing the temporary session and autoClose option 
> turned on everything works as expected.
>
> Regards,
> Lukasz

-- 
steve at hibernate.org
http://hibernate.org



More information about the hibernate-dev mailing list