0
Hello,
I have a Many to Many relationship between TEAM and NEWS. I am trying to create a method to insert a "NEWS". I am using Hibernate with Annotation to map the classes.
The Insert works and persists correctly in the NEWS table, but in the NEWS_TEAM table it does not insert. No error is shown...only it does not insert.
I did the test and added the record in the NEWS_TEAM table manually, direct in the database, and performed a simple listing using criteria, and it worked, but the Insert did not work.
Someone’s been through something like this?
Follows the method Newsbusinessimpl class Insert:
public void create(News news) {
Session session = null;
Transaction tx = null;
try {
session = PoliGenericDAO.getSessionFactory().openSession();
tx = session.beginTransaction();
session.save(news);
session.flush();
tx.commit();
} catch (Exception e) {
System.out.println("create.News.Error: " + e);
}finally {
session.close();
}
}
Follow the Entity NEWS:
...
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToMany(mappedBy = "newsList", targetEntity = Team.class, cascade = CascadeType.DETACH)
private Set<Team> teamList;
Follow the Entiadade TEAM:
@ManyToMany(cascade={CascadeType.MERGE,CascadeType.PERSIST}, fetch = FetchType.EAGER)
@JoinTable(name = "NEWS_TEAM", joinColumns = { @JoinColumn(name = "TEAM_ID") }, inverseJoinColumns = { @JoinColumn(name = "NEWS_ID") })
private Set<News> newsList;
Hello Fabio.. thanks for the reply...but the error was not what you said...I was already doing that way...sorry if I did not put the code. The mistake in my case was that I changed the notations from Many to Many. The "dominant entity" in the relation was wrong. Vlw helps!!
– Arthur Santos