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.