Given the definitions (ids omitted for simplicity):
@Entity
class A {
@OneToMany(mappedBy="a", cascade=CascadeType.ALL)
B b;
}
@Entity
class B {
@ManyToOne
@JoinColumn(nullable=false)
A a;
}
And the statements:
a.setB(b);
b.setA(a);
session.update(a);
session.flush();
We get PropertyValueException ("not-null property references a null or transient value") in the flush. But if we swap "a.setB(b)" with "b.setA(a)" no exception is thrown. It's as if "a.setB(b)" is firing an sql update with a null value in "b.a", regardless of the next setter and update lines.
We weren't getting this behavior before, it apparently started after moving from hibernate v3.6 to v4.3. How does hibernate decide to generate sql updates according to entity state changes or method calls in the entities and the session? Is there a configuration I can set to change it to the previous behavior?
Note: These statements are simplified, there's more code in between them.