Current code does not do update for child with null parent.
CATEGORY_PARENT_ID should be null instead of 1 for record with CATEGORY_ID = 1 after update.
What I need to change for proper child updating?
I am passing
child POJO to update method, here is toString() of it (
parent is null):
Code:
{"id":2}
DbUnit setup dataset:
Code:
<dataset>
<CATEGORY CATEGORY_ID="1"
<CATEGORY CATEGORY_ID="2"
CATEGORY_PARENT_ID="1"/>
</dataset>
DbUnit expected dataset:
Code:
<dataset>
<CATEGORY CATEGORY_ID="1"/>
<CATEGORY CATEGORY_ID="2"/>
</dataset>
Java code:
Code:
@OneToOne( cascade = {CascadeType.ALL})
@JoinColumn(name = "CATEGORY_PARENT_ID")
@NotFound(action = NotFoundAction.IGNORE)
private Category parent;
@OneToMany( orphanRemoval = true, mappedBy = "parent", cascade = {CascadeType.ALL})
@NotFound(action = NotFoundAction.IGNORE)
private List<Category> children;
//...
getHibernateTemplate().merge(entity);