← Back to team overview

dhis2-devs team mailing list archive

Problem with session factory and hibernate

 

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

Follow ups