Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 85168 invoked from network); 2 Apr 2009 06:30:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Apr 2009 06:30:10 -0000 Received: (qmail 43463 invoked by uid 500); 2 Apr 2009 06:30:09 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 43407 invoked by uid 500); 2 Apr 2009 06:30:09 -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 43397 invoked by uid 99); 2 Apr 2009 06:30:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Apr 2009 06:30:09 +0000 X-ASF-Spam-Status: No, hits=2.4 required=10.0 tests=HTML_MESSAGE,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; Thu, 02 Apr 2009 06:30:00 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LpGQk-0006QV-Ng for users@openjpa.apache.org; Wed, 01 Apr 2009 23:29:38 -0700 Message-ID: <1238653778677-2573585.post@n2.nabble.com> Date: Wed, 1 Apr 2009 23:29:38 -0700 (PDT) From: "srini.krish" To: users@openjpa.apache.org Subject: Re: Inconsistent behaviour with Bi-directional One to Many Mapping. In-Reply-To: <49D3A920.3040205@jotobjects.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_41789_16590935.1238653778677" X-Nabble-From: srinivasan.krish@gmail.com References: <1238606979187-2570464.post@n2.nabble.com> <49D3A920.3040205@jotobjects.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_41789_16590935.1238653778677 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Paul, Thanks for your suggestion.. But even after implementing your suggestion I get the same result.. It persists once and next time it fails.. its inconsistent.. I made the following changes to the mapping.. @ManyToOne (optional=3Dfalse, CascadeType.ALL) Is this a defect? Best regards, Srini On Wed, Apr 1, 2009 at 11:20 PM, Paul Copeland (via Nabble) wrote: > Does it make any difference if you put the CascadeType.ALL on both sides? > > Does it make any difference if you put optional=3Dfalse on the ManyToOne = ? > > @ManyToOne (optional=3Dfalse, CascadeType.ALL) > > On 4/1/2009 10:29 AM, srini.krish wrote: >> Hi , >> =C2=A0I am trying to create a bidirectional one to many mapping and seei= ng >> inconsistent behaviour. If I enable trace persistence succeeds and if I >> disable it, it fails. The failure is due to foreign key violation. I thi= nk >> its due to the order of the execution of insert statements. The dependen= t >> table is inserted with rows first. >> >> Here is the outline of mapping I have done. >> (A person can have one or more address. Each address has an unique id an= d >> a person associated with it) >> public class Person { >> =C2=A0 =C2=A0 @Id >> =C2=A0 =C2=A0 private int Id; >> >> =C2=A0 =C2=A0 @Basic >> =C2=A0 =C2=A0 private String Name; >> >> =C2=A0 =C2=A0 @OneToMany (cascade=3DCascadeType.ALL, mappedBy=3D"person"= ) >> =C2=A0 =C2=A0 @OrderBy >> =C2=A0 =C2=A0 private Collection
addresses; >> } >> >> public class Address { >> =C2=A0 =C2=A0 @Id >> =C2=A0 =C2=A0 private int id; >> >> @ManyToOne >> @JoinColumn(name=3D"PersonId", nullable=3Dfalse) >> private Person person; >> } >> >> I try the following code >> >> =C2=A0//Create new person >> // Create new addresses(2) >> //To each address add the same person. >> //To the person add addressCollection.(size 2). >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 em.getTransaction().begin(); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 em.persist(person); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 em.getTransaction().commit(); >> >> When I do this, sometimes person is first persisted and address is next. >> This case passes. (This happen when trace is on). >> >> The other times, address is persisted first. This fails for want of pers= on >> id. (This happens when trace is at Info level). >> >> Can anybody please help me, if I am missing something? >> >> Best Regards, >> Srini >> > > > ________________________________ > This email is a reply to your post @ > http://n2.nabble.com/Inconsistent-behaviour-with-Bi-directional-One-to-Ma= ny-Mapping.-tp2570464p2570589.html > You can reply by email or by visting the link above. > > --=20 View this message in context: http://n2.nabble.com/Inconsistent-behaviour-w= ith-Bi-directional-One-to-Many-Mapping.-tp2570464p2573585.html Sent from the OpenJPA Users mailing list archive at Nabble.com. ------=_Part_41789_16590935.1238653778677--