Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 79098 invoked from network); 9 Dec 2008 11:36:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Dec 2008 11:36:09 -0000 Received: (qmail 89977 invoked by uid 500); 9 Dec 2008 11:36:21 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 89953 invoked by uid 500); 9 Dec 2008 11:36:20 -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 89942 invoked by uid 99); 9 Dec 2008 11:36:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Dec 2008 03:36:20 -0800 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Dec 2008 11:36:05 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LA0sQ-0000SF-9n for users@openjpa.apache.org; Tue, 09 Dec 2008 03:35:42 -0800 Message-ID: <1228822542295-1633496.post@n2.nabble.com> Date: Tue, 9 Dec 2008 03:35:42 -0800 (PST) From: holod To: users@openjpa.apache.org Subject: Can't persist detached object MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: serega.sheypak@gmail.com X-Virus-Checked: Checked by ClamAV on apache.org I'm in strange situation. I have an entity Person. I have an EJB stateless bean which has three methods: 1. public createPerson(Person newPerson){...} 2. public updatePerson(Person newPerson, Person oldPerson){...} 3. private attachFields(Person detachedPerson){...} When I'm creating Person, my logic goes this way: 1. Outside bean Person is constructed, but It can have detached entities. 2. Invoke stateless bean -> createPerson(newPerson); 3. Inside this method attachFields(newPerson) in invoked. Everything goes fine! All detached fields (for example only id of some referenced entity is specified) are attached, Person is successfully persisted. When I'm trying to update person, I get strange Exception (it's not strange, but I can't get why does in happen). 1. Invoke updatePerson(newPerson, oldPerson); oldPerson is attached entity, newPerson is a raw entity with detached referenced enitities. 2. delete referenced entities from oldPerson. 3. use em.flush(); to force deletion data from db. 4. set new fields from newPerson to oldPerson. 5 attachFields(oldPerson) now, oldPerson CAN'T have detached entities 6. use em.merge(oldPerson) to save newly created referenced entities And... I get exception: can't persist detached entity! and JPA prints entity class bla.bla2.SomeEntityClass + [it's key]. But It can't be so! I get this entity from EntityManager and save it to field of oldPerson. The same procedure works fine when I create Person. I don't understand what's going on. Is there any possibility to know more details about such exception? I've put logger.debug everywhere and I clearly see how every field of person is taked from EntityManager. -- View this message in context: http://n2.nabble.com/Can%27t-persist-detached-object-tp1633496p1633496.html Sent from the OpenJPA Users mailing list archive at Nabble.com.