Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 80284 invoked from network); 1 Sep 2009 13:37:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Sep 2009 13:37:39 -0000 Received: (qmail 46362 invoked by uid 500); 1 Sep 2009 13:37:39 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 46272 invoked by uid 500); 1 Sep 2009 13:37:38 -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 46262 invoked by uid 99); 1 Sep 2009 13:37:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 13:37:38 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of curtisr7@gmail.com designates 209.85.217.207 as permitted sender) Received: from [209.85.217.207] (HELO mail-gx0-f207.google.com) (209.85.217.207) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 13:37:28 +0000 Received: by gxk3 with SMTP id 3so6806504gxk.14 for ; Tue, 01 Sep 2009 06:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=XBgBXgZbOx2eZiVIwdpGB07P/qyRYj3N9Xas/p6PXh4=; b=kue11UPqptwo0DeLcm9ilGlmak8FKmmHR2pQuIIrJ62YnHPd7IOpp8GPhfWAGxhvDz S8NM4B/Dg4QnhOqqZGJjgrpYU4Bg9ZPOx15ffXT8frQmbklXDUNtq8imv3VFNcxmHfpE IHSLrGVtTgNsQ9ANtvon+G71tlAf0d6V3LveA= 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=j8edNlKdA+uPnx4PoWbnGudCXnBmrJ9UruAJVuQYcicR2+eE+aIKlBrFvyN0OPytkb LNP2bZOxgt1xs2DgVHpUd1aYhVxGfebp2AAu5pYniUZst9BUjooiSwc3ZzbspRju3MNi Uy5TrYFGj8+lfiOPZOhjqdpB4SYpMkJ4eLMwk= MIME-Version: 1.0 Received: by 10.151.20.15 with SMTP id x15mr10432645ybi.126.1251812226859; Tue, 01 Sep 2009 06:37:06 -0700 (PDT) In-Reply-To: <89c0c52c0909010632s6ee9f286rda4f27bc538b683c@mail.gmail.com> References: <1251740936567-3555069.post@n2.nabble.com> <1251809726486-3560316.post@n2.nabble.com> <89c0c52c0909010632s6ee9f286rda4f27bc538b683c@mail.gmail.com> Date: Tue, 1 Sep 2009 08:37:06 -0500 Message-ID: Subject: Re: How to persist then update in same transaction From: Rick Curtis To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=000e0cd4890c1b946b0472843f6e X-Virus-Checked: Checked by ClamAV on apache.org --000e0cd4890c1b946b0472843f6e Content-Type: text/plain; charset=ISO-8859-1 I would also suggest that you enhance [1] your Entities when you test, otherwise you test a different code path than what you run in WAS. Thanks, Rick On Tue, Sep 1, 2009 at 8:32 AM, Kevin Sutter wrote: > Why are you performing the merge()? Since you are doing all of this within > a single transaction and you are not detaching any of these entities, there > is no need to do the merge(). You have already persisted orgType earlier > in > your code path. So, go ahead and set the OwnerOrgId and then complete the > transaction. That should work for you. Let us know the results. > > Thanks > Kevin > > On Tue, Sep 1, 2009 at 7:55 AM, Diane J wrote: > > > > > My DAO tests inherit from Springs AbstractJpaTests which start/commit the > > transaction for me. > > The only differences are that when I deploy to websphere, websphere > handles > > the transactions and in test spring does and the other difference is that > I > > enhance the classes when I deploy and donot when testing. > > > > I switched out openjpa with hibernate and hibernate handles this code > fine. > > > > > > Rick Curtis wrote: > > > > > > When running your application in JSE mode, are you calling > > > em.getTransaction().begin(commit())? I'm willing to bet you aren't and > > > that > > > is why your test works in JSE, but fails on WAS. > > > > > > -Rick > > > > > > On Mon, Aug 31, 2009 at 12:48 PM, Diane J > wrote: > > > > > >> > > >> I do the following in one transaction: > > >> > > >> OrgType orgType = new OrgType(); > > >> getOrgTypeDAO().persist(orgType); > > >> Organization org = new Organization(); > > >> org.setOrgName("Test"); > > >> org.setOrgTypeId(orgType.getOrgTypeId()); > > >> getOrganizationDAO().persist(org); > > >> orgType.setOwnerOrgId(org.getOrgId()); > > >> getOrgTypeDAO().merge(orgType); > > >> > > >> And the merge throws this exception: > > >> > > >> WTRN0074E: Exception caught from before_completion synchronization > > >> operation: > > >> org.apache.openjpa.persistence.InvalidStateException: The generated > > value > > >> processing detected an existing value assigned to this field: > > >> com.adp.ei9.common.entity.OrgType.orgTypeId. This existing value was > > >> either > > >> provided via an initializer or by calling the setter method. You > either > > >> need to remove the @GeneratedValue annotation or modify the code to > > >> remove > > >> the initializer processing. > > >> at > > >> org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:483) > > >> at > > >> org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:463) > > >> at > > >> > > >> > > > org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:682) > > >> at > > >> > > >> > > > org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:134) > > >> at > > >> > > >> > > > org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:519) > > >> at > > >> > > >> > > > org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2823) > > >> at > > >> org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39) > > >> at > > >> > > >> > > > org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:959) > > >> at > > >> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1948) > > >> at > > >> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1908) > > >> at > > >> > > > org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1826) > > >> at > > >> > > >> > > > com.ibm.ws.uow.ComponentContextSynchronizationWrapper.beforeCompletion(ComponentContextSynchronizationWrapper.java:65) > > >> at > > >> > > >> > > > com.ibm.tx.jta.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:289) > > >> at > > >> > > >> > > > com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:150) > > >> at > > >> > com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2222) > > >> at > > >> > > >> > > > com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:486) > > >> at > > >> com.ibm.tx.jta.TransactionImpl.processCommit(TransactionImpl.java:978) > > >> at > > com.ibm.tx.jta.TransactionImpl.commit(TransactionImpl.java:913) > > >> at > > >> com.ibm.ws.tx.jta.TranManagerImpl.commit(TranManagerImpl.java:369) > > >> at > com.ibm.tx.jta.TranManagerSet.commit(TranManagerSet.java:161) > > >> at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:915) > > >> at > com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:228) > > >> at > > >> > > >> > > > com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:561) > > >> at > > >> com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:4512) > > >> at > > >> > > >> > > > com.adp.ei9.esb.test.EJSLocalStatelessJPATester_80c7ee76.testPersistAndMergeOwnerId(EJSLocalStatelessJPATester_80c7ee76.java:138) > > >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > >> at > > >> > > >> > > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45) > > >> at > > >> > > >> > > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) > > >> at java.lang.reflect.Method.invoke(Method.java:599) > > >> at > > >> > > >> > > > com.ibm.etools.utc.model.ReflectionMethodModel.invoke(ReflectionMethodModel.java:65) > > >> at > > >> > com.ibm.etools.utc.servlet.InvokeServlet.invoke(InvokeServlet.java:113) > > >> at > > >> > com.ibm.etools.utc.servlet.InvokeServlet.doPost(InvokeServlet.java:374) > > >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) > > >> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) > > >> at > > >> > > >> > > > com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1443) > > >> at > > >> > > >> > > > com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:790) > > >> at > > >> > > >> > > > com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443) > > >> at > > >> > > >> > > > com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:175) > > >> at > > >> > > >> > > > com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91) > > >> at > > >> > > com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:859) > > >> at > > >> > > >> > > > com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1557) > > >> at > > >> > > > com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:173) > > >> at > > >> > > >> > > > com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455) > > >> at > > >> > > >> > > > com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384) > > >> at > > >> > > >> > > > com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83) > > >> at > > >> > > >> > > > com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1772) > > >> at > > >> > > >> > > > com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) > > >> at > > >> > > >> > > > com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) > > >> at > > >> > > >> > > > com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) > > >> at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) > > >> at > > com.ibm.io.async.ResultHandler.complete(ResultHandler.java:202) > > >> at > > >> > > >> > > > com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:766) > > >> at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896) > > >> at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527) > > >> > > >> > > >> This is expected to have a generated id because I already persisted > the > > >> entity. This only fails on websphere and not in my testcase where the > > >> transactions are not set to managed. > > >> > > >> These are my jpa props: > > >> > >> value="managed" /> > > >> > key="openjpa.ConnectionFactoryMode" > > >> value="managed" /> > > >> > >> value="operation-order" /> > > >> > > >> My test jpa props are: > > >> > >> key="openjpa.jdbc.SynchronizeMappings" > > >> value="buildSchema(ForeignKeys=true)" /> > > >> > >> > > >> > > >> > > > value="org.apache.openjpa.jdbc.sql.H2Dictionary(useGetObjectForBlobs=false)" > > >> /> > > >> > >> value="operation-order" /> > > >> > > >> > > >> -- > > >> View this message in context: > > >> > > > http://n2.nabble.com/How-to-persist-then-update-in-same-transaction-tp3555069p3555069.html > > >> Sent from the OpenJPA Users mailing list archive at Nabble.com. > > >> > > > > > > > > > > -- > > View this message in context: > > > http://n2.nabble.com/How-to-persist-then-update-in-same-transaction-tp3555069p3560316.html > > Sent from the OpenJPA Users mailing list archive at Nabble.com. > > > --000e0cd4890c1b946b0472843f6e--