Delay betwen persist and find of a relationship [message #531943] |
Thu, 06 May 2010 10:48  |
Eclipse User |
|
|
|
I facing the folowing problem.
a) I have an entity A with a OneToOne relationship with B with fetch EAGER
b) I populate A and B properties
c)I persist A
d)The database is updated correctly: table A and B.
e)I make a find of A with the same ID, the properties of A comes correctly, except the B relationship that comes with null
f)I wait aroud 10 minutes, and repeat the find, now the relationship B appears.
I'm using the eclipselink implementation of weblogic 11g.
Any hint?
Thanks. Mauro.
|
|
|
|
|
Re: Delay betwen persist and find of a relationship [message #532281 is a reply to message #532017] |
Fri, 07 May 2010 14:57  |
Eclipse User |
|
|
|
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.20539 seconds