Hello everyone.
I have entity Parent with set of children like this:
Code:
@Entity
public class Parent extends BaseEntity {
***other fields***
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "PARENT_CHILD", joinColumns = { @JoinColumn(name = "PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
private Set<Child> children = new HashSet<Child>(0);
***setters/getters***
}
Code:
@Entity
public class Child extends BaseEntity {
***other fields***
***setters/getters***
}
I use GenericDAO to persist and load data.
Let say:
Code:
Parent parent1 = new Parent();
parent1.setName("parentName");
parentDao.save(parent1);
Persists parent1 to database. Everything is fine.
Later I try to add child for this parent:
Code:
Parent managedParent = parentDao.findParentByName("testName");
Child child1 = new Child();
child1.setName("childName");
managedParent.getChildren().add(child1);
if (!dryRun) {
parentDao.update(managedParent);
} else {
// do not persist any changes if this is only dry run
}
So, even when dryRun is TRUE, child persists to database after flush.
Any idea, how to avoid this auto flushing?
I tried to set flushType like this:
Code:
entityManager.setFushMode(FlushModeType.COMMIT);
but this did not help.
Please help me :)