|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
back pointers - detached objectsEclipseLink 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 _______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
|
|
Re: 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.
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence |
|
|
Re: 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:
_______________________________________________ eclipselink-users mailing list eclipselink-users@... https://dev.eclipse.org/mailman/listinfo/eclipselink-users |
| Free embeddable forum powered by Nabble | Forum Help |