Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 48622 invoked from network); 19 Jul 2007 17:31:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Jul 2007 17:31:09 -0000 Received: (qmail 77133 invoked by uid 500); 19 Jul 2007 17:30:45 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 77117 invoked by uid 500); 19 Jul 2007 17:30:45 -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 77108 invoked by uid 99); 19 Jul 2007 17:30:45 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2007 10:30:45 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@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, 19 Jul 2007 10:30:42 -0700 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IBZpV-0002Hd-Ss for users@openjpa.apache.org; Thu, 19 Jul 2007 10:30:21 -0700 Message-ID: <11694049.post@talk.nabble.com> Date: Thu, 19 Jul 2007 10:30:21 -0700 (PDT) From: Pinaki Poddar To: users@openjpa.apache.org Subject: RE: Collection field part of a compound primary key In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: ppoddar@apache.org References: X-Virus-Checked: Checked by ClamAV on apache.org The domain model requires to define a compound identity for HolidayElement {HolidayDate, ParentHoliday} -- is that right? If this is the case, OpenJPA supports this feature as it allows a Relation to be part of compound identity for an Entity. the outline of the model can be: ========================================== @Entity class Holiday { @Id long hid; @OneToMany(mappedBy="parent") List elements; } =========================================== @Entity @IdClass(HolidayAsPartOfCompoundId.class) class HolidayElement { @Id Date date; @Id @ManyToOne Holiday parent; } =========================================== public class HolidayAsPartOfCompoundId { public Date date; // same name and type of HolidayElement's first identity field public long hid; // same name and type of Holiday's identity // Of course, you have to write equals() and hashCode() method of this compound Id class. =============================================== Further reading http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_oid_entitypk http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_overview_pc_identitycls Find attached the Holiday classes. Holiday is formed by several HolidayElements. A HolidayElement is mainly identified by its date, but several HolidayElement can share the same date if they are from diffetent Holidays. Here the primary Key is formed by the date and the Holiday id (which is a foreign key to Holiday). -- View this message in context: http://www.nabble.com/Collection-field-part-of-a-compound-primary-key-tf4110891.html#a11694049 Sent from the OpenJPA Users mailing list archive at Nabble.com.