Reputation: 55
I've got a bit of experience with spring, but I'm completely new to Hibernate, especially in combination with Spring: I want to have a Many-to-Many relationship between two tables (author, publication). The table is generated, but nothing is inserted...
Part of Author.java:
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "writes", joinColumns = {@JoinColumn(name = "authorId")}, inverseJoinColumns = {@JoinColumn(name = "publicationId")})
private Set<Publication> publications = new HashSet<Publication>();
part of Publication.java:
@ManyToMany(mappedBy = "publications")
private Set<Author> authors = new HashSet<Author>();
Is there something I forgot?
Thanks!!!!
Edit
here's the code which should save everything to my database:
@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";
}
Upvotes: 0
Views: 1418
Reputation: 597016
You are missing two important things:
session.save(..)
/ entityManager.persist(..)
(depending on whether you use JPA).I'd suggest reading a tutorial, which will explain these basic principles.
Upvotes: 1