openjpa-users mailing list archives

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

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.


Mime
View raw message