← Back to team overview

dhis2-devs team mailing list archive

Fatal error in save method of HibernateGenericStore clazz

 

Hi devs and Lars,

Surely that, we've got a hidden trouble when using the "*save*" method in *
HibernateGenericStore<T>* class here. Maybe call it is a fatal error.

Have a look at this error message:
*
**ERROR 11:03:42,172 Error while executing action (ExceptionInterceptor.java
[http-8080-6])
java.lang.ClassCastException:
org.hisp.dhis.regularexpression.RegularExpressionLib cannot be cast to
java.lang.Integer at
org.hisp.dhis.hibernate.HibernateGenericStore.save(HibernateGenericStore.java:146)
*

(In which, RegularExpressionLib is my defined class)

This error occurred in when trying to add/save a new record in a table where
has the primary-key is a composite-id.

Currently, the method "save" which is being defined like below:

    public final int save( T object )
    {
        return (Integer) sessionFactory.getCurrentSession().save( object );
    }

My opinion/suggestion in this case is that *SHOULD NOT* cast the type of
returned value like that, Integer for instance.

The "save" method of Session class now returns to an object as the instance
of Serializable class. Btw, if not mistaken, remembered that this method
usually returns the id of the new added record. So, this casting would right
if and only if the storing table contains a simple primary-key, "id" for
example.

If the primary-key is not a single key but is a composite key then the
problem would be happened like the example's above.

Give me your thought and any suggestion? Or how fix it?

Takk to all.

-- 
Hieu.HISPVietnam
Good Health !

Follow ups