Note that there are some explanatory texts on larger screens.

plurals
  1. POspring transactional cpool. Which one do I use?
    primarykey
    data
    text
    <p>I originally set up spring with xapool, but it turns out that's a dead project and seems to have lots of problems.</p> <p>I switched to c3p0, but now I learn that the @Transactional annotations don't actually create transactions when used with c3p0. If I do the following it will insert the row into Foo even through an exception was thrown inside the method:</p> <pre><code>@Service public class FooTst { @PersistenceContext(unitName="accessControlDb") private EntityManager em; @Transactional public void insertFoo() { em.createNativeQuery("INSERT INTO Foo (id) VALUES (:id)") .setParameter("id", System.currentTimeMillis() % Integer.MAX_VALUE ) .executeUpdate(); throw new RuntimeException("Foo"); } } </code></pre> <p>This is strange because if I comment out the @Transactional annotation it will actually fail and complain about having a transaction set to rollback only:</p> <pre><code>java.lang.IllegalStateException: Cannot get Transaction for setRollbackOnly at org.objectweb.jotm.Current.setRollbackOnly(Current.java:568) at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:421) at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:576) at org.hibernate.ejb.QueryImpl.executeUpdate(QueryImpl.java:48) at com.ipass.rbac.svc.FooTst.insertFoo(FooTst.java:21) at com.ipass.rbac.svc.SingleTst.testHasPriv(SingleTst.java:78) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160) at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233) at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333) at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217) at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197) at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) </code></pre> <p>So, clearly it notices the @Transactional annotation. But, it doesn't actually set autocommit to off at the start of the method.</p> <p>Here is how I have transactional stuff setup up in the applicationContext.xml. Is this correct? If not, what is this supposed to be?</p> <pre><code>&lt;bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/&gt; &lt;bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt; &lt;property name="transactionManager" ref="jotm"/&gt; &lt;property name="userTransaction" ref="jotm"/&gt; &lt;property name="allowCustomIsolationLevels" value="true"/&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="txManager" proxy-target-class="false"/&gt; </code></pre> <p>After a bunch of searching I found a connection pool called Bitronix, but their spring setup page describes stuff about JMS which doesn't even make any sense. What does JMS have to do with setting up a connection pool?</p> <p>So I'm stuck. What am I actually supposed to do? I don't understand why the connection pool needs to support transactions. All connections support turning autocommit on and off, so I have no idea what the problem is here.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload