I would like to save two entities with the following relationship:
@Entity
public class Synonyme {
@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name="ID", nullable = false)
private List<Term> terms = new ArrayList<>();
}
@Entity
public class Term {
private String word;
public static createTerm(String word, Synonyme newSyn, Long someothercriteria) {
Term term = new Term();
...
newSyn.addTerm(term);
}
}
And I want to save them like this:
Synonyme newSyn= Synonyme.createSynonyme ();
entityManager.persist(newSyn);
for(String word : words) {
Term term = Term.createTerm(word, newSyn, 0L );
}
entityManager.flush();
These codes work fine in Junit-Test (The Junit-Test uses an in-memory database of spring) but if I use them in the real database I got the following exception:
Caused by: javax.persistence.PersistenceException: org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 2; expected: 1
I don't understand this exception. What does it mean and what I could do?