Thanks Pinaki,
I will try to update my code as per your suggestion, however this
should be a nice to have API in OpenJPA itself.
Thanks and Regards,
Nitish Kumar
On Mon, Mar 23, 2009 at 7:25 PM, Pinaki Poddar <[email protected]> wrote:
>
> Hi,
> Following suggestion as per Nitish will work with few caveats.
> 1. It will not work for detached instances. Because detached instances can
> not access ClassMetaData.
> 2. The loop to search through fields can go wrong (because indexing is not
> one-to-one in all cases) and not necessary if ClassMetaData is available.
> The correct way is
> ClassMetaData metaData = sm.getMetaData();
> FieldMetaData fmd = metaData.getField(property);
> return sm.getLoaded().get(fmd.getIndex());
> 3. For detached instance, to get ClassMetaData, one will need somehow to
> access
>
> OpenJPAConfiguration.getMetaDataRepositoryInstance().getCachedMetaData(pc.getClass());
> then the rest will follow.
>
> public static boolean isPropertyLoaded(Object entity, String property) {
> PersistenceCapable pc = (PersistenceCapable) entity;
> StateManagerImpl sm = (StateManagerImpl)
> pc.pcGetStateManager();
> ClassMetaData metaData = sm.getMetaData();
> FieldMetaData[] fields = metaData.getFields();
> int dx = 0;
> for (int j = 0; j < fields.length; j++) {
> if (fields[j].getName().equals(property)) {
> dx = j;
> break;
> }
> }
> return sm.getLoaded().get(dx);
> }
>
> jlawmi wrote:
> >
> >
> > Thanks Nitish. In hibernate calling a getter doesn't force
> initialization,
> > at least on many-one fields, but I'll try it out. Since openjpa doesn't
> > use cglib that makes sense.
> >
> > --James
> >
>
>
> -----
> Pinaki Poddar http://ppoddar.blogspot.com/
>
> http://www.linkedin.com/in/pinakipoddar
> OpenJPA PMC Member/Committer
> JPA Expert Group Member
> --
> View this message in context:
> http://n2.nabble.com/hibernate-conversion-items-tp2511309p2521187.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>