Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 15960 invoked from network); 2 Mar 2011 17:12:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Mar 2011 17:12:23 -0000 Received: (qmail 91163 invoked by uid 500); 2 Mar 2011 17:12:23 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 90953 invoked by uid 500); 2 Mar 2011 17:12:21 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 90943 invoked by uid 99); 2 Mar 2011 17:12:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Mar 2011 17:12:20 +0000 X-ASF-Spam-Status: No, hits=3.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of curtisr7@gmail.com designates 209.85.214.174 as permitted sender) Received: from [209.85.214.174] (HELO mail-iw0-f174.google.com) (209.85.214.174) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Mar 2011 17:12:14 +0000 Received: by iwn34 with SMTP id 34so170947iwn.33 for ; Wed, 02 Mar 2011 09:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=P1un82NiVWNEnTGGgPBVa+1ryaEUkD1+7fUG450fTaY=; b=Bsvm1vnZj8fLvENgQKLg3rtPByA4KrV1wJOaTm+LgKLE+H9c1SGEJwHfRmmO3ZTNT/ gthoHJnpCewBbrU1lHd7vb6wfAJuKZz2htqmOl4e+NTEzxyDmjnb/zLktBZl7zlaaxpl SwWu1hf51/1NVk1OtJAnjaI1kWaj1NncUbte8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=ZZ9Ug8ooF8if2jNiN7BRJHETXpwPJGtErwEWP8e2goxmtakJ4JrWi6hVs/MzH3BZdh C11jnWwO6PcqcLrwHiEEJ0uZVmQgQ57Lbix4vbFZEgB0v/orrI3LwB3fykVX17DtWabd PZTJYMKiSzFUfvbJ8AW2i/Piao6x2vNDsGT4k= MIME-Version: 1.0 Received: by 10.231.30.70 with SMTP id t6mr97344ibc.165.1299085912608; Wed, 02 Mar 2011 09:11:52 -0800 (PST) Received: by 10.231.36.200 with HTTP; Wed, 2 Mar 2011 09:11:52 -0800 (PST) In-Reply-To: <64C85E9C-01DE-4233-B62A-52C56D9877D0@mayah.jp> References: <64C85E9C-01DE-4233-B62A-52C56D9877D0@mayah.jp> Date: Wed, 2 Mar 2011 11:11:52 -0600 Message-ID: Subject: Re: Optimistic lock problem From: Rick Curtis To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=0003255735f25a90ac049d83027a X-Virus-Checked: Checked by ClamAV on apache.org --0003255735f25a90ac049d83027a Content-Type: text/plain; charset=ISO-8859-1 Kawanaka - I'm going to start with my typical first question.... How are you enhancing your Entities? Can you post the contents of your persistence.xml file? Thanks, Rick On Wed, Mar 2, 2011 at 10:31 AM, KAWANAKA Shinya wrote: > Hi list, > > I encountered the weird situation that an optimistic lock violation > happened. I would like you to judge this is my fault or a bug. > > First I created an entity listed on here (https://gist.github.com/851075). > Then I wrote several tests that used the entity. In the following test, an > optimistic lock violation happened. > > === CODE STARTS HERE === > EntityManager em = emf.createEntityManager(); > { > em.getTransaction().begin(); > for (int i = 0; i < 10; ++i) { > Questionnaire q = new Questionnaire("id" + i, "eventId", > "question", i, "answerText"); > em.persist(q); > } > // em.flush(); // (1) > em.getTransaction().commit(); > } > > { > em.getTransaction().begin(); > // em.flush(); // (3) > Query q = em.createQuery("DELETE FROM Questionnaires t"); > q.executeUpdate(); > em.getTransaction().commit(); // (2) > } > > em.close(); > === CODE END HERE === > > In (2) the exception happened. The stack trace is attached at the last. > When I changed the field type of 'questionNo' to Integer (int -> Integer), > the violation did not happen. > > Some one advised me to use flush() at (1), but it did not help. > > When I added (3) and traced the function, I found that > ImplHelper.getUpdateField(sm) in AbstractUpdateManager#populateRowManager > returned a dirty flag that said the 'questionNo' was dirty. > > === CODE HERE === > } else if ((dirty = ImplHelper.getUpdateFields(sm)) != null) { > update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr, > store, customs, false); > === END === > > I only used a single thread, so I don't think the entities were changed in > the other threads. (Remember that the field type of 'questionNo' was changed > to Integer, the code worked.) > > Does anyone know why the violation happens? > > My environment is > Mac OS X Snow leopard, Sun Java 6, and OpenJPA-2.0.1. > > > > Exception in thread "main" > org.apache.openjpa.persistence.RollbackException: Optimistic locking errors > were detected when flushing to the data store. The following objects may > have been concurrently modified in another transaction: > [entity.Questionnaire-id3, entity.Questionnaire-id1, > entity.Questionnaire-id5, entity.Questionnaire-id2, > entity.Questionnaire-id6, entity.Questionnaire-id0, > entity.Questionnaire-id8, entity.Questionnaire-id9, > entity.Questionnaire-id4, entity.Questionnaire-id7] > at > org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:584) > at client.Test.run(Test.java:44) > at client.Test.main(Test.java:17) > Caused by: > org.apache.openjpa.persistence.OptimisticLockException: Optimistic locking > errors were detected when flushing to the data store. The following objects > may have been concurrently modified in another transaction: > [entity.Questionnaire-id3, entity.Questionnaire-id1, > entity.Questionnaire-id5, entity.Questionnaire-id2, > entity.Questionnaire-id6, entity.Questionnaire-id0, > entity.Questionnaire-id8, entity.Questionnaire-id9, > entity.Questionnaire-id4, entity.Questionnaire-id7] > at > org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2291) > at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2139) > at > org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2037) > at > org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1955) > at > org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81) > at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1479) > at > org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:925) > at > org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:560) > ... 2 more > Caused by: > org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock > violation was detected when flushing object instance > "entity.Questionnaire-id3" to the data store. This indicates that the > object was concurrently modified in another transaction. > FailedObject: entity.Questionnaire@72940b84 > at > org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:123) > at > org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:81) > at > org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99) > at > org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87) > at > org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550) > at > org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:107) > 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:731) > at > org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131) > ... 9 more > > > -- > Kawanaka Shinya > http://mayah.jp/ > > > > > > > --0003255735f25a90ac049d83027a--