|Re: Delay betwen persist and find of a relationship [message #532281 is a reply to message #532017]
||Fri, 07 May 2010 18:57
| Chris Delahunt
Registered: July 2009
This is because the relationship from A to B is marked insertable = false, updatable = false; essentially that it is read-only. Since new A objects won't have this relationship, it starts off as null and will not change for as long as it is in the cache unless the NRO_INT_B field is changed (through the commiting A's changes to the nroIntB attribute or through changes outside JPA), and hte Entity is refreshed. |
By turning the cache off, or waiting for the object to be purged/garbage collected from the cache, it causes the relationship to be read in/refreshed from the database, causing changes to the NRO_INT_B to show up. You can verify this by calling em.refresh(yourEntity) after your transaction commits and see that the A->B relationship will be set.
Ways around this
1) turn off the shared cache. This might not be the ideal solution, as the shared cache may provide some performance improvements for your app.
2) remove one of the fields from the A entity. For instance, if you have the A->B relationship, you can call a.b.id to get the value that is in A's NRO_INT_B field. Or you can use em.find(B.class, a.nroIntB) to get the B.
3) explicietly refresh the object when you make changes that affect the A->B relationship
Powered by FUDForum
. Page generated in 0.13671 seconds