Hi Laird,
I haven't tested any of this out, but I'd guess that OpenJPA (and apparently
other providers) have loaded your @ManyToOne relationship before you call
the accessor method. FetchMode.LAZY is a hint to the provider, not a mandate
(relevant section of the spec follows) :

Section 9.1.18, page 179 in my copy:

The EAGER strategy is a requirement on the persistence provider runtime that
data must be eagerlyfetched. The LAZY strategy is a hint to the persistence
provider runtime that data should be fetched
lazily when it is first accessed. The implementation is permitted to eagerly
fetch data for which the
LAZY strategy hint has been specified. In particular, lazy fetching might
only be available for Basic
mappings for which property-based access is used.


If the field was loaded by the provider there may be no reason to think that
it's dirty and we need to fetch it from the database (em.refresh will force
a reload).

It's possible that we could detect this case. Basically you have two fields
 (read-only and read-write) in an entity mapped to the same column. Once the
RW field has been updated we could reset the isLoaded attribute on the other
one - that should trigger a reload from the database when you call the
accessor method. I'd have to look at the relevant code a bit to make sure
but it sounds possible.

Are you doing this in many places throughout your app, or is this a
one-off?

-mike

On Fri, Aug 14, 2009 at 11:33 AM, ljnelson <ljnel...@gmail.com> wrote:

>
> On Fri, Aug 14, 2009 at 12:17 PM, Ravi P Palacherla (via Nabble) <
> ml-user+194843-327306...@n2.nabble.com<ml-user%2b194843-327306...@n2.nabble.com>
> <ml-user%2b194843-327306...@n2.nabble.com<ml-user%252b194843-327306...@n2.nabble.com>
> >
> > wrote:
>
> > 2.2    Persistent Fields and Properties
> > If property-based access is used and lazy fetching is specified, portable
> > applications should not directly access the
> > entity state underlying the property methods of managed instances until
> > after it has been fetched by the persistence provider.
>
>
> Sure; I'm using field-based access, so this one doesn't apply.
>
>
> > 3.2.7.1    Merging Detached Entity State
> > The persistence provider must not merge fields marked LAZY that have not
> > been fetched: it must ignore such fields when merging.
> >
>
> Sure; this means that if I have an entity, E5, that has a lazy field to an
> E6 that has never been set, then if I merge E5 to E6, E5's null E6
> reference
> shouldn't be used to wipe out any E6-related state that might exist on
> disk.  That's not the issue here either.
>
> Thanks for dredging up these references, however.
>
> Best,
> Laird
>
> --
> View this message in context:
> http://n2.nabble.com/insertable-updatable-%3D-false-question-tp3439111p3446109.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Reply via email to