Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] back pointers - detached objects

I think I understand what we are doing.  We find an object, then close the entity manager, then trigger the lazy load on the detached object and the entity manager needs to create a clone of the original object.

James Sutherland wrote:
c.visits.get(0).chart != c 
    
Should always be false (object identity is always maintained).  This is odd.

What configuration are you using?
I think that this can be an issue in JEE outside of a transaction context,
but should never occur in JSE or inside a transaction context, unless you
have somehow corrupted your object model.

Also, ensure that you are using EclipseLink, some other JPA providers may
use proxies that make this fail.



Len Edmondson wrote:
  
EclipseLink Users,

We have in essence:

A chart has a collection of visits.

class Chart {
    @OneToMany(fetch=LAZY, mappedBy="chart", cascade={ALL})
    @PrivateOwned
    List<Visit> visits = new ArrayList<Visit>();
}

class Visit{
    @ManyToOne(fetch=LAZY)
    @JoinColumn(name="PATID")
    Chart chart;
}

And for a Chart c;

    c.visits.get(0).chart != c

When we trigger a lazy fetch is the child object's parent reference is 
to a newly created object. 
Is there a way to request that the parent reference of the child object 
be identical to the parent?
Said another way, we already have the Chart object, we don't need EL to 
fetch it again, but rather simply refer to it.
Setting fetch=EAGER solves the problem, but we lose the desirable 
performance advantage of the lazy behaviour.

To work around this, in our code we include code based on this pattern.
Accessor method is responsible for fixing up the parent references.

List<Visit> getVisits(){
       for (Visit v : visits) {
          v.setChart(this);
       }
       return visits;
}

I hope this is clear.

    Leonard
    US Oncology
    Berkeley


    

-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
  

Back to the top