Reputation: 324
Iam trying to use the Datanucleus API to configure a M:N relation between two tables "which do not know about each other" as follows:
Books:Authors
@PersistenceCapable
public class Book{
@Persistent(primaryKey = "true")
@Column(name = "isbn", allowsNull = "false")
private int userId;
private String isbnCode;
private Str5ing title;
@Persistent(table="BOOK_AUTHOR")
@Join(column="isbn")
@Element(column="authorId")
Collection<Author> bookAuthors = new HashSet<Author>();
}
@PersistenceCapable
public class Author{
@Persistent(primaryKey = "true")
@Column(name = "author_id", allowsNull = "false")
private int authorId;
private String firstName;
private Str5ing lastName;
@Persistent(table="BOOK_AUTHOR")
@Join(column="authorId")
@Element(column="isbn")
Collection<Book> bookAuthors = new HashSet<Book>();
}
Now, as per this link of JDO's mapping, I expect a third table, to be created as the join table, with a new Id column.
What bugs me are two questions:
How do I get over the problem 2? I can live with problem 1 for a version or two but that needs to be resolved too.
Can the Zens of JDO please help?
Upvotes: 0
Views: 158
Reputation: 11531
Things to fix.
mappedBy
to link the 2 relation fields; you need to add that so then it is bidirectional. If this was supposed to be 2 independent 1-N relations then I don't see how you can share a join table, since data inserted from one side would get out of step with the data from the other sideNot sure what you mean by "An identity column as mentioned in the link above is NOT getting created."; You mean the "ADPT_PK_IDX" in the link ? don't think that applies in all cases.
For an M-N relation I would refer to this link as opposed to yours which was 1-N
Upvotes: 1