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

> 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 
-- 
View this message in context: http://www.nabble.com/back-pointers---detached-objects-tp24946952p25045601.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top