mnimer / dphibernate

Automatically exported from code.google.com/p/dphibernate
0 stars 0 forks source link

NPE on transient methods in entity #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. define transient methods in hibernate entity (only setter or getter)
2. when object is transleting it,s thows NPE on line:
pd.getReadMethod().invoke();
           ^^^null.invoke();
(when entity contains only setter of property pd)

or
pd.getWriteMethod().invoke();
           ^^^null.invoke();

(when entity contains only getter of property pd)

error in classes:
HibernateSerializer - 189
HibernateDeserializer - 186,190

version:
dpHibernate1.0.13

Original issue reported on code.google.com by ivan.yu....@gmail.com on 25 Jun 2008 at 4:03

GoogleCodeExporter commented 9 years ago
Here's a fixed version for the writemethod: 

private Object readBean(Object obj)
    {
        try
        {
            BeanInfo info = Introspector.getBeanInfo(obj.getClass());
            for (PropertyDescriptor pd : info.getPropertyDescriptors())
            {
                String propName = pd.getName();
                if (!"class".equals(propName) && !"annotations".equals(propName) && 
!"hibernateLazyInitializer".equals(propName))
                {
                    Object val = pd.getReadMethod().invoke(obj, null);
                    if (val != null)
                    {
                        Object newVal = translate(val, pd.getPropertyType());

                        Method writeMethod = pd.getWriteMethod();
                        if (writeMethod == null) {
                             if (Log.isDebug())
                                    Log.getLogger("Endpoint.AMF").debug("No writemethod exists for property " +
                                                   pd.getName() + " in bean of class " + obj.getClass().toString() +
                                                   " - no changes from the client can be persisted to this property.");
                        }
                        else {
                             writeMethod.invoke(obj, newVal);
                        }
                    }
                }
            }
        } 
        catch (Exception ex)
        {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
        return obj;
    }

same kind of thing will apply for the read method.

Original comment by ryeb...@gmail.com on 9 Aug 2008 at 7:19

GoogleCodeExporter commented 9 years ago
Seriously, this needs to be fixed.

Original comment by davidtro...@gmail.com on 4 Sep 2009 at 4:57

GoogleCodeExporter commented 9 years ago
Persistence is handled using change messaging, instead of object graphs now.  
Sending change messages on server-side read-only properties does not cause an 
exception (since 2.0RC5).

Original comment by martypit...@gtempaccount.com on 15 Mar 2011 at 3:18