【发布时间】:2019-04-30 09:10:54
【问题描述】:
我需要更新关系表的值。
我在关系表中有book_id 和author_id,我从Book 表中获得Idvalue 和Author 表的Id 值,我想从book_id 更改author_id。
我使用 Grails 进行了此操作,但没有成功。 我正在使用包含 Hibernate 和 Spring 的 Grails 框架。
Book bookToEdit = Book.findById(bookId)
Author newAuthor = Author.findById(authorId)
BookAuthor bookAuthor = BookAuthor.findByBook(bookToEdit)
bookAuthor.author = newAuthor
bookAuthor.save(flush:true)
当我调试此代码并提交我的更改时,我收到了作者的原始 ID,而不是提交的更改。
【问题讨论】: