0
更新對象
我有以下類:休眠執行刪除查詢時,我嘗試在春天
@Entity
@Table(name="tbl_books")
public class Book{
private int id_book;
private String isbn;
private Set<Author> authors;
@ManyToMany(cascade=CascadeType.ALL, fetch= FetchType.EAGER)
@JoinTable(name="tbl_books_tbl_authors",
joinColumns={@JoinColumn(name="id_book")},
inverseJoinColumns= {@JoinColumn(name="id_author")})
public Set<Author> getAuthors() {
return authors;
}
public void setAuthors(Set<Author> authors) {
this.authors = authors;
}
這是BookController的功能更新圖書的信息:
@RequestMapping(method=RequestMethod.POST)
public String dataBook(@Valid BookBean bb, BindingResult result){
if (result.hasErrors()){
return "redirect:/books/formBook";
}
booksService.saveBook(bb);
return "redirect:/books";
}
在booksService我有這樣的一個:
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void saveBook(BookBean lb) {
DataParser dp = new DataParser();
booksDAO.sBook(dp.fromBookBeanToBook(lb));
}
在booksDAO:
@Override
public void sBook(Book book) {
sessionFactory.getCurrentSession().saveOrUpdate(book);
}
然後,當我嘗試從形式更新圖書Hibertate做到這一點:
Hibernate: update tbl_books set date=?, isbn=? where id_book=?
Hibernate: delete from tbl_books_tbl_authors where id_book=?
爲什麼休眠做到這一點,我怎麼能解決這個問題?