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:[EMAIL PROTECTED] 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 <http://us.rd.yahoo.com/evt=49679/*http://searchmarketing.yahoo.com/arp/ sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50 > on your site using Yahoo! Search Marketing. <http://us.rd.yahoo.com/evt=49679/*http://searchmarketing.yahoo.com/arp/ sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50 > 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.