Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 60320F563 for ; Mon, 8 Apr 2013 16:45:15 +0000 (UTC) Received: (qmail 78286 invoked by uid 500); 8 Apr 2013 16:45:15 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 78254 invoked by uid 500); 8 Apr 2013 16:45:15 -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 78246 invoked by uid 99); 8 Apr 2013 16:45:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Apr 2013 16:45:15 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of maxtorzito@gmail.com designates 209.85.215.41 as permitted sender) Received: from [209.85.215.41] (HELO mail-la0-f41.google.com) (209.85.215.41) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Apr 2013 16:45:09 +0000 Received: by mail-la0-f41.google.com with SMTP id er20so464426lab.14 for ; Mon, 08 Apr 2013 09:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=TgserMf/hlF4vP+l9nSdej1yWFtD9vAOn/E/2GiITnQ=; b=r947jrhzjdcOL4RE8RLuL3S13E//s7bNGhH5+LpQ/V6EbrDPy5AtP83bYAVuUlY2hv ShUIWN9p+nhqwAlr2kBaUpQY19rgN3q30UzY6CgamFyMwx3NZGkIDoSqBkVUMTFSL+42 oZqTqdVUAAM4Ijf4e3PzFUH/POUyryKKk8snrdAge824LYB4tbN0Uw6bD57C8MaXfh4i ijs8uqsepvl/3shWvwhXAm+Ja1Nh9vwxjXL8EON3LN1lPxncl5ibVVXTHYXhqAOveF3Z wgkT9B8PhPbmBvXVPcPj2hydVc6BwRaza5s/YLbHvOmBWEXen4BrFyzyT65jOGPOT1yF Ekwg== MIME-Version: 1.0 X-Received: by 10.112.156.42 with SMTP id wb10mr11981902lbb.32.1365439488468; Mon, 08 Apr 2013 09:44:48 -0700 (PDT) Received: by 10.112.6.73 with HTTP; Mon, 8 Apr 2013 09:44:48 -0700 (PDT) Date: Mon, 8 Apr 2013 11:44:48 -0500 Message-ID: Subject: Insert new record + update child object From: =?ISO-8859-1?Q?Jos=E9_Luis_Cetina?= To: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=089e012296f2ac2cfc04d9dc27d7 X-Virus-Checked: Checked by ClamAV on apache.org --089e012296f2ac2cfc04d9dc27d7 Content-Type: text/plain; charset=ISO-8859-1 Hi. I have a problem with insert and updating a reference in the same entity. Im trying to insert a new object (Exam) that has a reference to another object (Person) and at the same time i want to update an attribute (birthDate) of the Person object. The update never happens although i set CascadeType to ALL. The only way this works is doing a persist and after that a merge operation. Is this normal? Do i have to change something?? I dont like the idea of a "manual update" using merge in the Person object because i don't know how many objects (child object of Exam) the user want to update. Entities: public class Exam{ @ManyToOne(cascade= CascadeType.ALL) @JoinColumn(name = "person_id") public Person person; ...... } public class Person{ private Date birthDate; @OneToMany(mappedBy = "person") private List exams ....... } public class SomeClass{ public void someMethod(){ exam = new Exam() person.setBirthDate(new Date()); exam.setPerson(person); someEJB.saveExam(exam); } } public class someEJB(){ public void saveExam(Exam exam){ ejbContext.getUserTransaction().begin(); em.persist(exam); //THIS WORKS em.merge(exam.getPerson()); ejbContext.getUserTransaction().commit(); } } Do i have to use the MERGE method for every child object? Here is the same question from other user: http://stackoverflow.com/questions/11029260/jpa-with-jta-persist-entity-and-merge-cascaded-child-entities --089e012296f2ac2cfc04d9dc27d7--