openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim McConnell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (OPENJPA-466) Primary key constraint violated using (Oracle) sequence to generate ID in multithreaded app
Date Wed, 13 May 2009 22:56:45 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-466?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12709197#action_12709197
] 

Tim McConnell commented on OPENJPA-466:
---------------------------------------

Hi Milosz, It's a little unclear to me how these changes will prevent duplicate sequence values.
And actually, I can easily create duplicates with these changes in trunk using the postgreSQL
database (by altering the number of entities created in the TestSequence testcase). See the
error/exception messages below and look for "duplicate key value violates unique constraint",
which is indicative of duplicate sequences getting created. This appears to be a regression
as these exceptions were eliminated using the previous patch.....

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.apache.openjpa.persistence.sequence.TestSequence
359  test  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.PostgresDictionary"
(PostgreSQL 8.3.6 ,PostgreSQL Native Driver PostgreSQL 8.3 JDBC3 with SSL (build 603)).
1406  test  INFO   [reflection invocation: (testMultiThreadedNativeSequences) [6 of 6]] openjpa.Runtime
- Starting OpenJPA 2.0.0-SNAPSHOT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 361.859 sec <<< FAILURE!
testMultiThreadedNativeSequences(org.apache.openjpa.persistence.sequence.TestSequence)  Time
elapsed: 361.765 sec  <<< ERROR!
org.apache.openjpa.persistence.sequence.TestSequence$ThreadingException: The 1 embedded errors
occured in the execution of 8 iterations of 6 threads: [reflection invocation: (testMultiThreadedNativeSequences)]
	at org.apache.openjpa.persistence.sequence.TestSequence.mttest(TestSequence.java:440)
	at org.apache.openjpa.persistence.sequence.TestSequence.mttest(TestSequence.java:334)
	at org.apache.openjpa.persistence.sequence.TestSequence.mttest(TestSequence.java:281)
	at org.apache.openjpa.persistence.sequence.TestSequence.mttest(TestSequence.java:275)
	at org.apache.openjpa.persistence.sequence.TestSequence.testMultiThreadedNativeSequences(TestSequence.java:66)
	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 junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at org.apache.openjpa.persistence.test.PersistenceTestCase.runBare(PersistenceTestCase.java:465)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at org.apache.openjpa.persistence.test.PersistenceTestCase.run(PersistenceTestCase.java:181)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	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:213)
	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
	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:345)
	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Nested Throwable #1: org.apache.openjpa.persistence.sequence.TestSequence$ThreadingException:
thread=Thread[reflection invocation: (testMultiThreadedNativeSequences) [1 of 6],5,main];threadNum=1;maxThreads=6;iteration=2;maxIterations=8
	at org.apache.openjpa.persistence.sequence.TestSequence$2.run(TestSequence.java:405)
Nested Throwable #1: java.lang.reflect.InvocationTargetException
	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.openjpa.persistence.sequence.TestSequence$1.run(TestSequence.java:337)
	at org.apache.openjpa.persistence.sequence.TestSequence$2.run(TestSequence.java:398)
Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:774393M fatal store error> org.apache.openjpa.persistence.RollbackException:
The transaction has been rolled back.  See the nested exceptions for details on the errors
that occurred.
	at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:559)
	at org.apache.openjpa.persistence.sequence.TestSequence.createManyPersonsAndEmployeesInSeparateTransactions(TestSequence.java:191)
	at org.apache.openjpa.persistence.sequence.TestSequence.testMultiThreadedNativeSequences(TestSequence.java:78)
	... 6 more
Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:774393M fatal general error> org.apache.openjpa.persistence.PersistenceException:
The transaction has been rolled back.  See the nested exceptions for details on the errors
that occurred.
	at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2266)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2113)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2011)
	at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1929)
	at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
	at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1453)
	at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:895)
	at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:548)
	... 8 more
Caused by: <openjpa-2.0.0-SNAPSHOT-r422266:774393M fatal general error> org.apache.openjpa.persistence.PersistenceException:
ERROR: duplicate key value violates unique constraint "entity_employee_pkey" {prepstmnt 24724157
INSERT INTO ENTITY_EMPLOYEE (id, firstName, lastName, salary) VALUES (?, ?, ?, ?) [params=(int)
256631, (String) 4_First_name_6912, (String) 4_Last_name_6912, (float) 6912.0]} [code=0, state=23505]
FailedObject: org.apache.openjpa.persistence.sequence.EntityEmployee@ff5a2b
	at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4383)
	at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4342)
	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:72)
	at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:141)
	at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:80)
	at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:97)
	at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:85)
	at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
	at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106)
	at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
	at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:672)
	at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
	... 15 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR: duplicate key value violates
unique constraint "entity_employee_pkey" {prepstmnt 24724157 INSERT INTO ENTITY_EMPLOYEE (id,
firstName, lastName, salary) VALUES (?, ?, ?, ?) [params=(int) 256631, (String) 4_First_name_6912,
(String) 4_Last_name_6912, (float) 6912.0]} [code=0, state=23505]
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:236)
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:69)
	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1080)
	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:286)
	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:286)
	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1579)
	at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:246)
	at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:116)
	... 25 more


Results :

Tests in error: 
  testMultiThreadedNativeSequences(org.apache.openjpa.persistence.sequence.TestSequence)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.


> Primary key constraint violated using (Oracle) sequence to generate ID in multithreaded
app
> -------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-466
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-466
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.0.0, 1.0.1, 1.1.0, 1.2.0
>         Environment: OpenJPA 1.0.0 (also tried 1.0.1 and 1.1.0-SNAPSHOT)
> Oracle XE 10g (JDBC driver 10.2.0.3.0)
> Windows XP Pro
>            Reporter: Frank Le
>            Assignee: Milosz Tylenda
>            Priority: Blocker
>             Fix For: 1.3.0, 2.0.0
>
>         Attachments: OPENJPA-466.patch, OPENJPA-466.patch
>
>
> Here's how I annotate the ID:
>     @Id
>     @SequenceGenerator(name = "FooSeq", sequenceName = "seq_foo", allocationSize = 20)
>     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FooSeq")
>     private Long id;
> Here's how I create the (Oracle) sequence:
> CREATE SEQUENCE seq_foo START WITH 1 INCREMENT BY 1;
> I get a primary key unique constraint violated in a multithreaded app i.e. it doesn't
happen in single-threaded!
> You can simply reproduce this error by either create blocking queue or blocking thread
pool say size 5 to insert 10000+ object.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message