我对 Spring 有一些经验,但我对 Hibernate 完全陌生,尤其是与 Spring 结合使用:我想在两个表(作者、出版物)之间建立多对多关系。该表已生成,但没有插入任何内容...
Author.java 的一部分:
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "writes", joinColumns = {@JoinColumn(name = "authorId")}, inverseJoinColumns = {@JoinColumn(name = "publicationId")})
private Set<Publication> publications = new HashSet<Publication>();
Publication.java 的一部分:
@ManyToMany(mappedBy = "publications")
private Set<Author> authors = new HashSet<Author>();
有什么我忘记了吗?
谢谢!!!!
编辑
这是应该将所有内容保存到我的数据库的代码:
@RequestMapping(value = PATHELEM + "/insertTest", method = RequestMethod.POST)
public String addAuthor(@ModelAttribute("object") DatabaseObject object,
BindingResult result) {
authorService.addAuthor(object.getAuthor());
publicationService.addPublication(object.getPublication());
return PATHELEM + "/insertEntryForm";
}