Let say I have classB inside classA, both are @Entity and @OneToOne
relationships between the two.
Let say I already persisted classA and classB and I want to update
variable b of the ClassA using following code.
I am trying to understand if the database effect of assigning a "new"
ClassB to variable b (Code piece-I below) is any different than
getting b first than updating B's member variables (Code piece -II) ?
// Pseudo code piece - I
startTransaction
X = findClassA
X.setb(new ClassB)
commitTransaction
// Pseudo code piece - II
startTransaction
X = findClassA
X.getb.setName("...)
commitTransaction
public class ClassA {
int idA;
@OneToMany(mappedBy = "myA", cascade = CascadeType.ALL,
targetEntity = classB, fetch = FetchType.EAGER)
ClassB b;
String name;
...
}
public class ClassB {
int idB
@OneToOne
@JoinColumn(name = "idA")
private ClassA myA;
....
}