0

我在长期更新 grails 中的一个域(图书馆)时遇到问题,我试图在添加新书后更新我的图书馆,但添加的书没有得到保存。

I have mapping of bookCollection in my domain Class Library as below:

@OneToMany(cascade = CascadeType.ALL, mappedBy = "Library")
    Collection<Book> bookCollection;


I am trying to add a new book to my Library(Initially there is no book in  bookColletion):

Library library = Library.get(1)
Book book=Book.get(1)
library.bookCollection.add(book)

and update it:
library.save(flush:true,failOnError: true)

Library is got saved but  my book is not.

I am using grails and JPA.

谢谢

4

1 回答 1

0

您没有设置关系的另一端librarybook.

Library library = Library.get(1)
Book book=Book.get(1)
library.bookCollection.add(book)
book.library = library; // <--- sets the other side of the relation
于 2013-04-23T10:30:47.183 回答