Skip to main content

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

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


Back to the top