openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: Lazy initialisation questions
Date Tue, 16 Dec 2008 15:52:45 GMT

Hi,
  Hopefully, you are familiar with configuration options that may be
relevant in similar scenarios. For example, DetachState flags such as
"AccessUnloaded". 

> *1. How do I figure out what fields of a detached object are
> uninitialized?*

The bit index of getLoaded() are same as the index used in ClassMetaData. So
the following *should* work (but I am writing this on-line without testing,
please verify)

PersistenceCapable pc = (PersistenceCapable)myEntity;
OpenJPAStateManager sm = (OpenJPAStateManager)pc.pcGetStateManager();
BitSet loaded = sm.getLoaded();
for (int i = 0; i < loaded.size(); i++) {
 FieldMetaData fmd = sm.getMetaData().getField(i);
 System.err.println(fmd.getFullName() + (loaded.get(i) ? ": loaded" ? ": not
loaded");
}

> 2. How do I get the id of a uninitialized single-valued association
> object?*

> I have seen this in some code sample (but, again, I need to know the 
> index of the Java field):

> Object proxy =
> ((OpenJPAStateManager)pc.pcGetStateManager()).getIntermediate(index);
> Object id = ((OpenJPAId)proxy).getIdObject();

> Is it reliable?

Bit hacky, might work. But what is the usage? If the single-valued
association object is not fetched during detach, the remote tier will not
have access to it anyway. If it has been fetched during detach, then there
will be more direct (and kosher) way to get its identifier's value. 

> *3. How do I recreate an OpenJPA detached object?*

  Tough. Thinking...
  But why?

-- 
View this message in context: http://n2.nabble.com/Lazy-initialisation-questions-tp1662940p1663486.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message