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 <[email protected]>: > 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 > <[email protected]>wrote: > >> Hi HIeu, >> >> On Wed, Jun 16, 2010 at 3:49 PM, Hieu Dang Duy <[email protected] >> > 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/%7Edhis2-devs> >>> Post to : [email protected] >>> Unsubscribe : >>> https://launchpad.net/~dhis2-devs<https://launchpad.net/%7Edhis2-devs> >>> More help : https://help.launchpad.net/ListHelp >>> >>> >> > > > -- > Hieu.HISPVietnam > Good Health ! > -- Sendt fra min mobile enhet _______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

