Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 54484 invoked from network); 20 Dec 2007 19:09:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Dec 2007 19:09:08 -0000 Received: (qmail 75516 invoked by uid 500); 20 Dec 2007 19:08:56 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 75490 invoked by uid 500); 20 Dec 2007 19:08:56 -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 75478 invoked by uid 99); 20 Dec 2007 19:08:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2007 11:08:56 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of marc.siegel.17@gmail.com designates 209.85.142.189 as permitted sender) Received: from [209.85.142.189] (HELO ti-out-0910.google.com) (209.85.142.189) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Dec 2007 19:08:34 +0000 Received: by ti-out-0910.google.com with SMTP id y6so3318tia.13 for ; Thu, 20 Dec 2007 11:08:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=qTDI2pDM6Hwhgn3ozXLPoQa23yGG10BcEOD7kPd4G6Q=; b=l2nL6KE7vfCVeXaC5HZh+Ox15QzNuQLhjk07IrIGSiVrOzUM+CXudD9F1wnumqvrH0ZKqLhukHR9BcaPOLFlvGH9zTU58kClAnf+0FQSCGsUz8624DAj0dw7Jly+oIB9yBKGA7jLpOX3d0tSCdZYQdReq7Ar6XAVQ8lPkin0ihU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=HuqBJXAgCNxXfidFXsxCgWesqMovzrp5Hwz6b3cZ/NuMAReFCBRBHgUJkqwhGEE10lkgISr8GIblXiVNFsVFwZnzBJoyYVWzEiy+3Ts/1RqSL86wtyloslyFFz8h2fOzCbYrzNG3tCshdVIXmFxlmEpCjHbanJX7mxRGiZLyRSw= Received: by 10.110.47.7 with SMTP id u7mr319114tiu.58.1198177716395; Thu, 20 Dec 2007 11:08:36 -0800 (PST) Received: by 10.70.26.19 with HTTP; Thu, 20 Dec 2007 11:08:36 -0800 (PST) Message-ID: <2f58dd5d0712201108g46c12443l5b938490fff40b2c@mail.gmail.com> Date: Thu, 20 Dec 2007 14:08:36 -0500 From: "Marc Siegel" To: users@openjpa.apache.org Subject: Re: @PreUpdate always called? In-Reply-To: <20071220171815.GC16275@sfu.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <2f58dd5d0711011121t21e2b80fyf8dc1a16a8c998ae@mail.gmail.com> <2f58dd5d0711011220m7d8b2ff3ubec63fdeeabedd0b@mail.gmail.com> <7262f25e0711011501j5b843ee0l99ef04aae1cdaab0@mail.gmail.com> <2f58dd5d0711011509t5e02ebffhf7accbbf70fdc77e@mail.gmail.com> <14180794.post@talk.nabble.com> <2f58dd5d0712180644h1fc01b3emc894a53ca1d1b50d@mail.gmail.com> <4769145B.4030206@cyberspaceroad.org> <476A5E0C.6050302@cyberspaceroad.org> <20071220171815.GC16275@sfu.ca> X-Virus-Checked: Checked by ClamAV on apache.org I second this - I am NOT using Spring, and I see this behavior. -Marc On Dec 20, 2007 12:18 PM, Tedman Leung wrote: > I'm not entirely sure it's a problem with "your spring transaction usage". > > I have the exact same problem although I'm also using springs > transactions, I'm using the spring annotated transactions. > > I find that if I just call entityManager.find() on an object that once the > transaction completes it calls @PreUpdate even if I haven't modified any > fields. > > I would have assumed that a transaction.commit() would not cause > @PreUpdate to be called if no changes were made to the object. I tried > looking in the ejb-3_0 spec but it didn't seems to cleary indicate if it > should or should not be called. > > I guess I'll try writing a simple test case which shows this. > > > > > I wrote the smallest possible test case to demonstrate the problem (the > > undesired updates after the commit on a transaction that only had reads). > > > > I discovered that the way I was managing Spring Framework's transaction > > handling was causing my problem. > > > > I thought I had to supply the Spring Framework transaction manager with the > > EntityManager that I was using for a thread outside Spring. However, I > > don't need to. It's enough to give Spring the EntityManagerFactory. > > > > The call to the Spring internals with the EntityManager causes the problem, > > although I'm not likely to have time to check out why. This is how I was > > doing it: > > > > TransactionSynchronizationManager.bindResource( > > entityManagerFactory, new EntityManagerHolder(entityManager)); > > > > In this way I was assuming that Spring would use this entityManager, > > however for reasons unknown Spring's JpaTransactionManager was ignoring > > this entityManager and calling the EntityManagerFactory to get another - > > the EMF is injected into JpaTransactionManager in the IoC config (from my > > ContextManager): > > > > > class="org.springframework.orm.jpa.JpaTransactionManager"> > > > > > factory-method="getEntityManagerFactory" /> > > > > > > > > > > So OpenJPA's EntityManagerFactory provides a single EntityManager to a > > single thread - presumably storing it in a ThreadLocal - rather than > > creating a new one with entityManagerFactory.createEntityManager(). > > > > I presume this is an OpenJPA feature, because I didn't find it in the > > persistence specification. > > > > What do you OpenJPA developers think? > > > > > > thanks > > Adam > > > > > > > > Adam Hardy on 19/12/07 12:53, wrote: > > >Will an Eclipse project be fine for the OpenJPA developers? How about > > >the lib jars? Will m2eclipse and maven be acceptable (certainly would be > > >easiest)? > > > > > >Marc - are you using Spring Framework transaction management? > > > > > >regards > > >Adam > > > > > >Marc Siegel on 18/12/07 14:44, wrote: > > >>It would be worth it to some of us users. Anything that could be done > > >>to get this fixed would help many people. > > >> > > >>-Marc > > >> > > >>On Dec 17, 2007 6:34 PM, Adam Hardy wrote: > > >>>>I also had a situation where OpenJPA fired updates on unchanged > > >>>>entities after > > >>>committing the transaction, for all fields all the time. > > >>> > > >>>For instance, one pojo only had 2 string fields and a Long primary > > >>>key. OpenJPA > > >>>updated both string fields after the commit. > > >>> > > >>>I'm using the extended persistence context without any versioning, > > >>>and the only > > >>>configuration I set is the JDBC connection properties. > > >>> > > >>>Unfortunately I fixed it without figuring out where exactly the > > >>>problem was. > > >>>Sorry. I think what I had done is to begin a transaction, commit it, > > >>>and then > > >>>start another and whatever I pulled into the second transaction, > > >>>OpenJPA did an > > >>>update on. > > >>> > > >>>If you think this is worth putting a test case together for, let me > > >>>know. I > > >>>wasn't quite sure whether running a second transaction after the > > >>>first on the > > >>>same entity manager was legitimate according to the JPA spec. > > >>> > > >>> > > >>>Shelley writes: > > >>>>I am seeing a similar issue with OpenJPA unnecessarily calling an > > >>>>UPDATE on > > >>>>every commit. > > >>>> > > >>>>It appears that on every commit(), all of my entity's Date fields > > >>>>(TemporalType.TIMESTAMP) are being updated even though they have not > > >>>>changed. > > >>>> > > >>>>UPDATE MY_ENTITY SET timeField = ?, version = ? WHERE id = ? AND > > >>>>version = ? > > >>>>[params=(Timestamp) 2007-12-05 15:08:18.927, (int) 2, (int) 50, > > >>>>(int) 1] > > >>>> > > >>>>My current workaround is to clear the persistence context after each > > >>>>commit, > > >>>>but this obviously is not desirable and shouldn't be necessary. Any > > >>>>ideas > > >>>>as to why this might be occurring, or how to prevent it? I am using > > >>>>the > > >>>>majority of default OpenJPA properties (version LockManager, optimistic > > >>>>locking, etc), although I have attempted to modify some of these > > >>>>properties > > >>>>to prevent this problem, so far with no success. > > > > > > > > > > -- > Ted Leung > tedman@sfu.ca > > It is easier to speak wisely than to act wisely. >