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 D97467A95 for ; Thu, 22 Sep 2011 16:01:38 +0000 (UTC) Received: (qmail 72437 invoked by uid 500); 22 Sep 2011 16:01:38 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 72404 invoked by uid 500); 22 Sep 2011 16:01: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 72396 invoked by uid 99); 22 Sep 2011 16:01:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2011 16:01:38 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=MSGID_MULTIPLE_AT,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [212.227.17.9] (HELO moutng.kundenserver.de) (212.227.17.9) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2011 16:01:30 +0000 Received: from dcsWin701 (p50996dbd.dip0.t-ipconnect.de [80.153.109.189]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0LwZNH-1R9JyU1d5r-0180zV; Thu, 22 Sep 2011 18:01:09 +0200 From: "Michael Spiro" To: References: <000001cc78fd$208ef300$61acd900$@spiro@dcs-caesar.de> <1316704155094-6820601.post@n2.nabble.com> In-Reply-To: <1316704155094-6820601.post@n2.nabble.com> Subject: AW: Diamond model and foreign keys Date: Thu, 22 Sep 2011 18:01:10 +0200 Message-ID: <001201cc7940$d8c7c3a0$8a574ae0$@spiro@dcs-caesar.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Acx5OajcPjW9GV+JSnOIrL/Hh6xOOAABrDXA Content-Language: de X-Provags-ID: V02:K0:KHlcor0NuDquZy+x3dby8AnDXnKbgPg2u0x3r4Sxpcs 9tlBm0VzvezMgfZc6gMeUY4ddabd7HWbiNvB4sLr9Jc9BAWmgZ 3cfhjEV3n7z5wLnDuYOkYAdVzcHhGWs49V3OlBXwqozSP70QjB 7fiOstddID0iX7qCPDcGfG5l42VuCsK0J0HNz4/f3rtHsavHY5 NGOOz7l7C/Z0jVemT4eXU/mVHMaLAK51dDkgvq5CsF6Qufc3Ds CZet/14+3dbG6Byc8JKDdBPQ5G2gOtCpIu5JOo8UKW9mIrCZwR LNYPoNgxnx0g6ctrGeo2cCtqJrbWuqu/A66vwIRv5yTiEaPKFK q5dtd1r06VgCpzmW3t9nnX2Z4hq71NdK70zfKMHhByMNxZC1Ne yVvk03Q/MoUrg== X-Virus-Checked: Checked by ClamAV on apache.org Hi Pinaki, thanks for the advice. Actually, a solution similar to b) (with Object = as a part of EmbeddedKey) was implemented in my original project as the error first occured. I'll try the annotation with @ForeignKey first. In every case, it's rather strange that OpenJPA makes everything correct having = less information (no link between Price and Room), but writes an error when = it has extra information that actually makes the whole thing consistent. By the way, the duplicate mapping comes from the OpenJPA reverse mapping tool. Wouldn't it be reasonable if the tool would generate the classes without this double mapping? Kind regards, Michael Spiro > -----Urspr=FCngliche Nachricht----- > Von: Pinaki Poddar [mailto:ppoddar@apache.org] > Gesendet: Donnerstag, 22. September 2011 17:09 > An: users@openjpa.apache.org > Betreff: Re: Diamond model and foreign keys >=20 > Hi Michael, > The problem could be in domain model/mapping definition. The model > follows > a "duplicate mapping" approach. Let me explain what I mean by > "duplicate > mapping" in the context of your application. >=20 > public class Seasontime { > @ManyToOne(fetch=3DFetchType.LAZY, cascade=3DCascadeType.MERGE) > @JoinColumn(name=3D"hotel_idhotel", columnDefinition=3D"INT") > private Hotel hotel; >=20 > @Id > @Column(name=3D"hotel_idhotel", columnDefinition=3D"INT") > private int hotelIdhotel; >=20 > Now in this model, both fields "Hotel hotel" and "int hotelIdhotel" > refer to > the same "logical" thing i.e. a Hotel object, but in two different > ways. A > JPA runtime, however, has little clue that they mean the same thing. > To make JPA understand this "implicit" sameness of these two fields, > there > are two possibilities > a) annotate "int hotelIdhotel" with @ForeignKey(implicit=3Dtrue) (see > @ForeignKey documentation for details) > b) remove the ""int hotelIdhotel" field altogether. Instead annotate > the > "Hotel hotel" as @Id. JPA 2.0 supports a object reference as a primary > key > either as a simple key or part of a compound key. I prefer this > approach > because it avoids the "duplicate mapping" problem and results into > cleaner > domain model. > Examples of such modeling technique can be found in OpenBooks example > distributed with OpenJPA. >=20 > ----- > Pinaki Poddar > Chair, Apache OpenJPA Project > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Diamond-model-and-foreign-keys- > tp6819272p6820601.html > Sent from the OpenJPA Users mailing list archive at Nabble.com.