Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Delay betwen persist and find of a relationship
Delay betwen persist and find of a relationship [message #531943] Thu, 06 May 2010 14:48 Go to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
Member
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 #531990 is a reply to message #531943] Thu, 06 May 2010 17:28 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Very odd.

Were both A and B new to begin with? Is the 1-1 cascade persist?

What type of caching are you using? Can you try disabling the shared cache (shared=false).

Do you have issues on your database that defers writes?


James : Wiki : Book : Blog : Twitter
Re: Delay betwen persist and find of a relationship [message #532017 is a reply to message #531990] Thu, 06 May 2010 18:58 Go to previous messageGo to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
Member
a) Problem solved disabling the shared cache. Thanks.

<property name="eclipselink.cache.shared.default" value="false"/>

b) I'm new to eclipselink, we are migrating our systems from openjpa to eclipselink. I have to study about cache policies of eclipselink.

c) Analizing more the entity, I saw a weird thing:

- the entity A has the id of entity B as a property too.
- when A is persisted, B already exists, and the id of B is setted to A.

@Entity
@Table(name = "A")
public class A {
  @Id
  private Integer nroIntA;

  @Column(name = "NRO_INT_B")  
  private int nroIntB;
  
  @OneToOne(fetch = FetchType.EAGER)
  @JoinColumn(name = "NRO_INT_B", insertable = false, updatable = false)
  private B b ;
}



Re: Delay betwen persist and find of a relationship [message #532281 is a reply to message #532017] Fri, 07 May 2010 18:57 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
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
Previous Topic:NamedNativeQuery
Next Topic:[Unidirectional OneToOne Relationships] eclipselink doesn't understand MapsId=" "
Goto Forum:
  


Current Time: Sun Dec 21 12:57:13 GMT 2014

Powered by FUDForum. Page generated in 0.02056 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software