← Back to team overview

dhis2-devs team mailing list archive

Re: Problem with session factory and hibernate

 

Hi,

are you testing this through the UI - if so did you remember to add

@Transactional

to the service layer class to enable transactions? This is necessary for
modifications to be persisted in db.


regards,

Lars

On Mon, Feb 8, 2016 at 3:57 PM, Yrjan Aleksander Frøyland Fraschetti <
yrjanaff@xxxxxxxxx> wrote:

> I have a problem with session factory and saving objects to the database
> using hibernate.
>
> The problem is that when I use
> sessionFactory.getCurrentSession().save(object), nothing is persisted. If I
> use a flush() after the save the object is persisted, but the next time an
> object is saved to the database a copy of the former object is saved again
> with a new id, together with the new object. Has anyone encountered this
> before?
>
>
> Method for persisting object:
>
> public class HibernateDataStatisticsStore extends HibernateGenericStore<DataStatisticsEvent> implements DataStatisticsStore
> {
>
>     @Override
>     public int addDataStatisticsEvent( DataStatisticsEvent dataStatistics )
>     {
>        	int id = (Integer) sessionFactory.getCurrentSession().save(dataStatistics);
>         sessionFactory.getCurrentSession().flush();
>         return id;
>
>     }
>
> Hibernate-mapping:
>
> <hibernate-mapping>
>   <class name="org.hisp.dhis.datastatistics.DataStatisticsEvent" table="datastatisticsevent">
>     <cache usage="read-write" />
>     <id name="id" column="eventid">
>       <generator class="native" />
>     </id>
>     <property name="type" column="eventtype">
>       <type name="org.hibernate.type.EnumType">
>         <param name="enumClass">org.hisp.dhis.datastatistics.EventType</param>
>       </type>
>     </property>
>     <property name="timestamp" column="timestamp" type="java.util.Date"></property>
>     <property name="userId" column="userid" type="int" ></property>
>   </class>
> </hibernate-mapping>
>
>
>
> Regards,
> Yrjan Fraschetti
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs
> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs
> More help   : https://help.launchpad.net/ListHelp
>
>


-- 
Lars Helge Øverland
Lead developer, DHIS 2
University of Oslo
Skype: larshelgeoverland
http://www.dhis2.org <https://www.dhis2.org/>

Follow ups

References