Long story short:
Recipe
contains
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.REMOVE}, mappedBy = "recipe")
private Set<RecipeRow> rows = new HashSet<>();
Row
contains:
@ManyToOne(cascade = CascadeType.REFRESH)`
@JoinColumn(name = "recipe_id")
private Recipe recipe;`
The Row
extends a mapped superclass with a tree structure (i.e. it contains a mapped parent
field which is of same type)
Right before the entity manager merge (of the recipe) all rows (and their information) are there. When it merges, it throws this (it's with regards to the row!!!):
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "name" violates
not-null constraint Detail: Failing row contains (11, 2015-08-22 13:53:33.276,
304170813849900523, 0, null, null, null, null, null, null, 1000, null,
null, null, null, null, null, null, null, null).
which is pretty much impossible because all mandatory fields are there.
Also, the ID sequence (of the row table) is increased, but no rows are persisted in the DB (postgres).
Am I missing something here? Is my question too broad?
Edit 1:
Alright, so this was a beginner's mistake, and also a stupid one.
The rows have a tree structure, right? And the saved collection contained ALL of them, as flat tree (ie list).
The problem is that the top rows had the abstract root as parent (which isn't transient), and the abstract root was trying to map itself.
Of course I didn't notice this in the debugging, because I was only looking at the rows, and at their mandatory fields, but not at the parent (which isn't mandatory).
Yep...