From open-jpa-dev-return-3045-apmail-incubator-open-jpa-dev-archive=incubator.apache.org@incubator.apache.org Mon Apr 02 19:50:40 2007 Return-Path: Delivered-To: apmail-incubator-open-jpa-dev-archive@locus.apache.org Received: (qmail 87964 invoked from network); 2 Apr 2007 19:50:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Apr 2007 19:50:20 -0000 Received: (qmail 91432 invoked by uid 500); 2 Apr 2007 19:50:27 -0000 Delivered-To: apmail-incubator-open-jpa-dev-archive@incubator.apache.org Received: (qmail 91407 invoked by uid 500); 2 Apr 2007 19:50:27 -0000 Mailing-List: contact open-jpa-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: open-jpa-dev@incubator.apache.org Delivered-To: mailing list open-jpa-dev@incubator.apache.org Received: (qmail 91398 invoked by uid 99); 2 Apr 2007 19:50:27 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2007 12:50:27 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of ppoddar@bea.com designates 66.248.192.39 as permitted sender) Received: from [66.248.192.39] (HELO repmmg02.bea.com) (66.248.192.39) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Apr 2007 12:50:18 -0700 Received: from repmmr02.bea.com (repmmr02.bea.com [10.160.30.72]) by repmmg02.bea.com (Switch-3.2.5/Switch-3.2.5) with ESMTP id l32JnNJG001323 for ; Mon, 2 Apr 2007 12:49:57 -0700 Received: from repbex01.amer.bea.com (repbex01.bea.com [10.160.26.98]) by repmmr02.bea.com (Switch-3.2.5/Switch-3.2.5) with ESMTP id l32JnNE2009507 for ; Mon, 2 Apr 2007 12:49:57 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C77560.0106FC8F" Subject: RE: composite ID w/ another composite ID as a field Date: Mon, 2 Apr 2007 12:48:15 -0700 Message-ID: <5C219175D559A64D8C2CC65E41D36856F06B56@repbex01.amer.bea.com> In-Reply-To: <391047.92493.qm@web39513.mail.mud.yahoo.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: composite ID w/ another composite ID as a field Thread-Index: Acd1Tj/s8ichpI03QmajXn8xzzwI2AADmDqw References: <391047.92493.qm@web39513.mail.mud.yahoo.com> From: "Pinaki Poddar" To: x-BEA-PMX-Instructions: AV x-BEA-MM: Internal-To-External X-Virus-Checked: Checked by ClamAV on apache.org ------_=_NextPart_001_01C77560.0106FC8F Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello Jeff, OpenJPA supports the cited example where Page using a composite ID which in turn refers to Book's composite ID. Book/Page/Library classes work with a) openjpa-0.9.7 (do not know whether observed errors are due to usage of earlier 0.9.6 version) b) following modifications in Page.book field (with a + sign) @Id @Column(nullable = false) @ManyToOne (cascade = CascadeType.ALL) + @JoinColumns({ + @JoinColumn(name="book_library_LIBRARY_NAME", referencedColumnName="library_LIBRARY_NAME"), + @JoinColumn(name="book_BOOK_NAME", referencedColumnName="BOOK_NAME") }) private Book book; where the JoinColumns specification refers to following schema (as per your Page/Book/Library class annotations): mysql> desc book; +----------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------------+--------------+------+-----+---------+-------+ | library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL | | | BOOK_NAME | varchar(255) | NO | PRI | NULL | | +----------------------+--------------+------+-----+---------+-------+ mysql> desc page; +---------------------------+--------------+------+-----+---------+----- --+ | Field | Type | Null | Key | Default | Extra | +---------------------------+--------------+------+-----+---------+----- --+ | book_library_LIBRARY_NAME | varchar(255) | NO | PRI | NULL | | | book_BOOK_NAME | varchar(255) | NO | PRI | NULL | | | PAGE_NUMBER | int(11) | NO | PRI | NULL | | +---------------------------+--------------+------+-----+---------+----- --+ Without explicitly naming the join columns, following error is generated: Caused by: <4|true|0.9.7-incubating-SNAPSHOT> org.apache.openjpa.persistence.ArgumentException: "crxxx.Page.book" does not supply a name for at least one declared column. Since this mapping can involve multiple columns or uses constant joins, each column must give either its name or a non-constant target. at org.apache.openjpa.jdbc.meta.MappingInfo.mergeJoinColumn(MappingInfo.jav a:1372) at org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:11 86) at org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja va:948) at org.apache.openjpa.jdbc.meta.ValueMappingInfo.getTypeJoin(ValueMappingIn fo.java:101) at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi eldStrategy.java:144) at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java: 117) at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru ntimeStrategyInstaller.java:77) at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja va:435) at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400) at org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(Cla ssMapping.java:810) at org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRep ository.java:316) at org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository .java:602) at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja va:489) ... 24 more NestedThrowables: <4|true|0.9.7-incubating-SNAPSHOT> org.apache.openjpa.persistence.ArgumentException: Field "crxxx.Book.pages" declares "crxxx.Page.book" as its mapped-by field, but this field is not a direct relation. at org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrateg y.map(RelationToManyInverseKeyFieldStrategy.java:123) at org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStr ategy.map(RelationCollectionInverseKeyFieldStrategy.java:92) at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java: 117) at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru ntimeStrategyInstaller.java:77) at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja va:435) at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400) at org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja va:781) at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570) ... Pinaki Poddar BEA Systems 415.402.7317 -----Original Message----- From: jeff [mailto:jeffrey.blattman@yahoo.com] Sent: Monday, April 02, 2007 12:42 PM To: open-jpa-dev@incubator.apache.org Subject: composite ID w/ another composite ID as a field say i have Library, Book, and Page classes. a Library has many Books, and a Book has many Pages. A Library's ID is it's name (simple). A Book's ID is a composite of it's name and it's owning Library's name (bidirectional relationship). A Page's ID is a composite of it's number and it's owning Book's ID, a BookID. so, the PageId class starts like: public class PageId implements Serializable { private int number; private BookId book; the error i'm getting is at runtime ... <4|true|0.9.6-incubating> org.apache.openjpa.persistence.ArgumentException: Field "com.mycompany.book.Book.pages" declares "com.mycompany.book.Page.book" as its mapped-by field, but this field is not a direct relation. first, is what i'm trying to do even valid? i suspect it is not, and the problem is that the fields of the ID class must be "simple" types (i believe the spec demands that). although, the error message is a little confusing so i am not sure. it occurs to me that another way to achieve this would be to add bookName and libraryName fields to the Page class, and add a @PrePersist method that populates them by calling book.getName() and book.getLibrary().getName(). but again this is messy because that data is already in the table because of the bidirectional relationship between the objects. as always, i'm open to "what are you an idiot?" responses if i am just going about trying to define the Library, Book, Page relationship in an obtuse manner. classes attached. ________________________________ The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it. ------_=_NextPart_001_01C77560.0106FC8F--