openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dick" <michael.d.d...@gmail.com>
Subject Re: What causes an optimistic exception?
Date Thu, 04 Jan 2007 21:12:03 GMT
By default OpenJPA uses optimistic transactions (ie the transaction does not
lock database records). Since the database records aren't locked there is a
chance that a second transaction can modify the record before the first one
completes. There's a better explanation in the OpenJPA manual here :
http://incubator.apache.org/openjpa/docs/openjpa-0.9.6-incubating/manual/manual.html#jpa_overview_trans_types.

The OptimisticException you're seeing in the log is thrown when OpenJPA
detects that a record has been changed by another thread. The exception
should be thrown back to the transaction manager though so there might be a
bug there, or something is intercepting it.

Does the problem occur when you run one test at a time, or does it only
occur if you run several of them at once? If you're running more than one
test and they touch the same rows of the database, that might explain why
you're getting the exception (but not why it isn't making it back to the
app).

That's my first guess. If you can easily reproduce the problem it might help
to turn on OpenJPA tracing and see if that shows two transactions using the
same entity.

Hope this helps,


On 1/4/07, Dain Sundstrom <dain@iq80.com> wrote:
>
> I'm getting this exception printed to my log, but my tests work.  Is
> my test doing something wrong?
>
> <2|false|0.9.6-incubating>
> org.apache.openjpa.util.OptimisticException: Optimistic locking
> errors were detected when flushing to the data store.  The following
> objects may have been concurrently modified in another transaction:
> [org.apache.openejb.test.entity.cmr.onetoone.ABean_JPA@2c4eaa]
>          at org.apache.openjpa.kernel.BrokerImpl.newFlushException
> (BrokerImpl.java:2077)
>          at org.apache.openjpa.kernel.BrokerImpl.flush
> (BrokerImpl.java:1927)
>          at org.apache.openjpa.kernel.BrokerImpl.flushSafe
> (BrokerImpl.java:1825)
>          at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion
> (BrokerImpl.java:1756)
>          at org.apache.openejb.core.TransactionManagerWrapper
> $TransactionWrapper.beforeCompletion(TransactionManagerWrapper.java:194)
>          at
> org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion
> (TransactionImpl.java:515)
>          at
> org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare
> (TransactionImpl.java:399)
>          at
> org.apache.geronimo.transaction.manager.TransactionImpl.commit
> (TransactionImpl.java:256)
>          at
> org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit
> (TransactionManagerImpl.java:264)
>          at org.apache.openejb.core.TransactionManagerWrapper.commit
> (TransactionManagerWrapper.java:58)
>          at
> org.apache.openejb.test.entity.cmr.AbstractCMRTest.completeTransaction
> (AbstractCMRTest.java:57)
>          at
> org.apache.openejb.test.entity.cmr.OneToOneTests.test07_BSetAExistingBNe
> wA(OneToOneTests.java:154)
>          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:585)
>          at org.apache.openejb.test.NumberedTestCase.runTestMethod
> (NumberedTestCase.java:135)
>          at org.apache.openejb.test.NumberedTestCase$1.protect
> (NumberedTestCase.java:120)
>          at junit.framework.TestResult.runProtected(TestResult.java:128)
>          at org.apache.openejb.test.NumberedTestCase.run
> (NumberedTestCase.java:123)
>          at org.apache.openejb.test.NumberedTestCase.run
> (NumberedTestCase.java:102)
>          at org.apache.openejb.test.TestSuite.run(TestSuite.java:46)
>          at org.apache.openejb.test.TestSuite.run(TestSuite.java:46)
>          at org.apache.openejb.test.TestSuite.run(TestSuite.java:46)
>          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:585)
>          at org.apache.maven.surefire.junit.JUnitTestSet.execute
> (JUnitTestSet.java:210)
>          at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSe
> t(AbstractDirectoryTestSuite.java:135)
>          at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute
> (AbstractDirectoryTestSuite.java:160)
>          at org.apache.maven.surefire.Surefire.run(Surefire.java:81)
>          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:585)
>          at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess
> (SurefireBooter.java:182)
>          at org.apache.maven.surefire.booter.SurefireBooter.main
> (SurefireBooter.java:743)
> Caused by: <2|false|0.9.6-incubating>
> org.apache.openjpa.util.OptimisticException: An optimistic lock
> violation was detected when flushing object instance
> "org.apache.openejb.test.entity.cmr.onetoone.ABean_JPA@2c4eaa" to the
> data store.  This indicates that the object was concurrently modified
> in another transaction.
> FailedObject:
> org.apache.openejb.test.entity.cmr.onetoone.ABean_JPA@2c4eaa
>          at
> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInterna
> l(PreparedStatementManagerImpl.java:96)
>          at
> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush
> (PreparedStatementManagerImpl.java:68)
>          at
> org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryR
> ow(OperationOrderUpdateManager.java:200)
>          at
> org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush
> (OperationOrderUpdateManager.java:86)
>          at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush
> (AbstractUpdateManager.java:86)
>          at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush
> (AbstractUpdateManager.java:69)
>          at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush
> (JDBCStoreManager.java:511)
>          at org.apache.openjpa.kernel.DelegatingStoreManager.flush
> (DelegatingStoreManager.java:127)
>          ... 37 more
>
>


-- 
-Michael Dick

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message