Access to transient fields as member variables appears not to be intercepted, unlike for persistent fields when using field access (declaring annotations on fields, not on getters). As a consequence, the value of a transient field that is not accessed through getters/setters becomes de-synchronized across multiple proxies for one and the same entity within a transaction.
Example
@Entity
public class LowLevel {
@Id
int id;
@Transient
public int counter1=0;
@Transient
public int counter2=0;
public int getCounter1() { return this.counter1; }
public void setCounter1(int counter1) { this.counter1=counter1; }
}
@Entity
public class HighLevel extends LowLevel {
public void doSomething() {
setCounter1(1);
this.counter2 = 1;
}
}
Now assume that you have a persistent instance of HighLevel, and somehow obtain two proxies P1 and P2, where P1 references the instance as a LowLevel (that's how you'd end up with two different proxies, as I understand).
From our observations, the following will happen:
P2.doSomething();
=> P1.getCounter1() == 1
=> P1.counter2 == 0
Is this observation correct and is this behavior intended?
|