openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <>
Subject RE: hibernate conversion items
Date Mon, 23 Mar 2009 13:55:35 GMT

  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
  then the rest will follow. 

public static boolean isPropertyLoaded(Object entity, String property) {
                PersistenceCapable pc = (PersistenceCapable) entity;
                StateManagerImpl sm = (StateManagerImpl)
                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;
                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            
OpenJPA PMC Member/Committer
JPA Expert Group Member
View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message