> i want the Page's ID to be based on it's number, and ALSO the > owning Book's name. i could make an ID class for Page, but
If you wanted to make the ID be based on it's number and the owning Book itself (i.e., not the name), you could do this with OpenJPA, but not with vanilla JPA. OpenJPA supports @Id fields on one-to-one and many-to-one fields: http://incubator.apache.org/openjpa/docs/latest/manual/manual.html#ref_g uide_pc_oid_entitypk Personally, I think thaht using the Book object as part of the PK is probably a better idea than using the Book's name, since it seems like the Book's name is not unique. However, if you really do want to use the Book's name, the only way to do so in OpenJPA is to make Book.name the @Id of the Book class, and use the syntax in the link I provided above. -Patrick -- Patrick Linskey BEA Systems, Inc. _______________________________________________________________________ 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. > -----Original Message----- > From: jeff [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 27, 2007 10:08 AM > To: open-jpa-dev@incubator.apache.org > Subject: composite ID based on "one" side of a bidirectional > one-many relationship > > say i have Book and Page classes. a Book has a name and can > also have many Pages. a Page has a number, and a reference to > the owning Book. > > i want the Page's ID to be based on it's number, and ALSO the > owning Book's name. i could make an ID class for Page, but > the fields of the ID class need to be simple types, so i > can't map them to the book field in Page ... ? > > i did get it to work by adding a bookName field to Page that > gets populated in the setBook() setter, and creating a PageId > that uses the Page's number and the simple bookName field. > > however, this seems wrong, as it results in redundant data > stored in the Page table. for example, the created table for > Page has NUMBER, BOOKNAME, and BOOK_BOOK_NAME columns, the > latter two of which are always the same. > > i am sure there's a best practice for this. any advice is appreciated. > > i have a test case for this i can send if my description is > not obvious, but my last attempt failed apache's spam filter. > > > > > --------------------------------- > Don't get soaked. Take a quick peek at the forecast > with theYahoo! Search weather shortcut. > 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.