Hello everybody! I have basic question. Unfortunately, I couldn't find clear answer. I was playing with annotations example from "Beginning Hibernate" book. The model has several classes, two of them have many to many relationship:
something like this: class Book { ... @ManyToMany Set<Author> authors; }
class Author { ... @ManyToMany Set<Book> books; }
then they create two books, two authors and add authors to books:
Book b1 = new Book(); Book b2 = new Book();
Author a1 = new Author(); Author a2 = new Author();
b1.authors.add(a1); b1.authors.add(a2); b2.authors.add(a1); b2.authors.add(a2);
and finally call session.save();
Everything is fine in database, if I open new session and get all objects I see each book has two authors and each author has two books. But right after session.save() the model is inconsistent- each book has two authors but each author has empty set of books. It looks very strange, after save() operation all objects are controlled by hibernate, I would expect consistent model. What do I miss?
Thank you, Andrey
|