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 CB35F7587 for ; Thu, 22 Sep 2011 15:09:42 +0000 (UTC) Received: (qmail 5026 invoked by uid 500); 22 Sep 2011 15:09:42 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 4984 invoked by uid 500); 22 Sep 2011 15:09:42 -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 4974 invoked by uid 99); 22 Sep 2011 15:09:42 -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 15:09:42 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Sep 2011 15:09:36 +0000 Received: from jim.nabble.com ([192.168.236.80]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1R6ktn-0005rj-3z for users@openjpa.apache.org; Thu, 22 Sep 2011 08:09:15 -0700 Date: Thu, 22 Sep 2011 08:09:15 -0700 (PDT) From: Pinaki Poddar To: users@openjpa.apache.org Message-ID: <1316704155094-6820601.post@n2.nabble.com> In-Reply-To: <000001cc78fd$208ef300$61acd900$@spiro@dcs-caesar.de> References: <000001cc78fd$208ef300$61acd900$@spiro@dcs-caesar.de> Subject: Re: Diamond model and foreign keys MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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. public class Seasontime { @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.MERGE) @JoinColumn(name="hotel_idhotel", columnDefinition="INT") private Hotel hotel; @Id @Column(name="hotel_idhotel", columnDefinition="INT") private int hotelIdhotel; 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=true) (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. ----- 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.