Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problems retrieving a joined entity object (Calling join methods on a recently created object doesn't work)
Problems retrieving a joined entity object [message #778767] Fri, 13 January 2012 14:46 Go to previous message
John Dugo is currently offline John Dugo
Messages: 12
Registered: October 2011
Junior Member
I am seeing an issue retrieving joined objects on a recently created (and merged) entity object.

Here is the scenario:

class A {
@Column("A_ID")
Long getObjectId();
void setObjectId(Long id);
}

class B {
@Column("B_ID")
Long getObjectId();
void setObjectId(Long id);
@Column("A_ID")
Long getAId();
void setAId(Long aId);
@JoinColumn(name="AID")
@ManyToOne(fetch=Lazy)
A getA();
void setA(A a);
}


The flow is as follows:

Object A is created and merged.
A a = new A();
a.setObjectId(1);
entityManager.merge(a);

Object B is created, the foreign key id for A is set, and merged:
B b = new B();
b.setObjectId(2);
b.setAId(1);
entityManager.merge(b);

Object B is loaded.

B b = m_entityManager.find(B.class,2)

A a = b.getA();
//a == null!

When I try to retrieve the joined A object off of B, it is always null. Now if I wait long enough and the cache is refreshed, calling b.getA() will correctly return the object.

All of these calls are happening in consecutive calls to the server, so the transactions are committed and the data is in the database. My cache is currently set to an isolation level of Shared using a cache type of Weak.

Note that I am never explicitly setting b.setA(a) before I call merge, but I dont feel like I should have to. I am setting the foreign key id and I have the join set to be lazily loaded.

Is there something that I am doing wrong or a setting that I am missing? I dont want to have to separately load the object, I should just be able to get it from the join.
 
Read Message
Read Message
Read Message
Previous Topic:DBWS: java.sql.SQLSyntaxErrorException
Next Topic:Extension Attributes- @VirtualAccessMethods
Goto Forum:
  


Current Time: Fri May 24 11:29:29 EDT 2013

Powered by FUDForum. Page generated in 0.01595 seconds