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**** 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 !

Hi HIeu,

Hi devs and Lars,

Surely that, we’ve got a hidden trouble when using the “save” method in HibernateGenericStore**** 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.

In my opinion, you should override the “save” method in your RegularExpressionLibDAO because we don’t have too much object with composite key.

Regards,
Quang

···

On Wed, Jun 16, 2010 at 3:49 PM, Hieu Dang Duy hieu.hispvietnam@gmail.com wrote:


Hieu.HISPVietnam
Good Health !


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp

Thank you. Perhaps, do as your opinion. But thought that is a template way.

Expecting, if can, we should re-write the “save” method in HibernateGenericStore**** class likes:

public final Serializable save( T object )
{
    return sessionFactory.getCurrentSession().save( object );
}
···

On Wed, Jun 16, 2010 at 4:21 PM, Quang Nguyen quangnguyen111@gmail.com wrote:

Hi HIeu,

On Wed, Jun 16, 2010 at 3:49 PM, Hieu Dang Duy hieu.hispvietnam@gmail.com wrote:

Hi devs and Lars,

Surely that, we’ve got a hidden trouble when using the “save” method in HibernateGenericStore**** 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.

In my opinion, you should override the “save” method in your RegularExpressionLibDAO because we don’t have too much object with composite key.

Regards,
Quang


Hieu.HISPVietnam
Good Health !


Mailing list: https://launchpad.net/~dhis2-devs

Post to : dhis2-devs@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp


Hieu.HISPVietnam
Good Health !

I see your point Hieu, but there is also a convenience aspect here.
Also, entities with composite primary keys are considered bad
practise. Like Quang says, in this case override or just don't use
genericstore. Lars

···

2010/6/16, Hieu Dang Duy <hieu.hispvietnam@gmail.com>:

Thank you. Perhaps, do as your opinion. But thought that is a template way.

Expecting, if can, we should re-write the "save" method in *
HibernateGenericStore<T>* class likes:

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

On Wed, Jun 16, 2010 at 4:21 PM, Quang Nguyen > <quangnguyen111@gmail.com>wrote:

Hi HIeu,

On Wed, Jun 16, 2010 at 3:49 PM, Hieu Dang Duy <hieu.hispvietnam@gmail.com >> > wrote:

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.

In my opinion, you should override the “save” method in your
RegularExpressionLibDAO because we don’t have too much object with
composite
key.

Regards,
Quang

--
Hieu.HISPVietnam
Good Health !

_______________________________________________
Mailing list:
https://launchpad.net/~dhis2-devs<https://launchpad.net/~dhis2-devs>
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe :
https://launchpad.net/~dhis2-devs<https://launchpad.net/~dhis2-devs>
More help : https://help.launchpad.net/ListHelp

--
Hieu.HISPVietnam
Good Health !

--
Sendt fra min mobile enhet