Hello,
 
Imagine a dom. model like class A { @Id long id; String name; @Lazy B b;
}; class B { @Id String code; /* ... other attributes ... */ }.
 
When doing a Query on A with a FetchGroup that excludes the A's b field,
or simply through a @Lazy annotation, OpenJPA stills always loads the FK
(c.f.
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/
ref_guide_fetch.html#ref_guide_fetch_impl
<http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual
/ref_guide_fetch.html#ref_guide_fetch_impl> , "Even when a direct
relation is not eagerly fetched, OpenJPA selects the foreign key columns
and caches the values."), so the 'code' of B that is in the A table.
That's good.
 
Question: How do you now actually access/get the value of that b's code,
the String? OpenJPA has it, in memory, but when you hold an instance a
of A, the instant you do a.getB().getCode(), of course it will lazy load
the full B - because it has no way of knowing that after the getB()
you'll do only a getCode() ... ;-) I trust this has been considered and
thought of, and there is a solution... how???
 
I feel like I'm looking for "the opposite the
EntityManager.getReference() method", if that makes any sense? Is the
OpenJPAEntityManager's Object getObjectId(Object o) the rescue here...
but how exactly? A String bCode = oem.getObjectId(a.getB()) will most
likely still lead to a lazy DB load, right? Is there any chance
something like this: class A { ... @Lazy B b; B getB() { return this.b;
} String getBCodeId() { return HOWTOGETTHEEM.getObjectId(b); } } - will
work? Or will simply passing the b field to getObjectId also lead to a
lazy load? If that's feasible, how to get an EM inside the getter?
 
Much appreciate any ideas!
 
Regards,
Michael
 

____________________________________________________________

• This email and any files transmitted with it are CONFIDENTIAL and intended
  solely for the use of the individual or entity to which they are addressed.
• Any unauthorized copying, disclosure, or distribution of the material within
  this email is strictly forbidden.
• Any views or opinions presented within this e-mail are solely those of the
  author and do not necessarily represent those of Odyssey Financial
Technologies SA unless otherwise specifically stated.
• An electronic message is not binding on its sender. Any message referring to
  a binding engagement must be confirmed in writing and duly signed.
• If you have received this email in error, please notify the sender immediately
  and delete the original.

Reply via email to