facebook

Hibernate : getting old data though change appears in DB

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #234684 Reply

    slepit
    Member

    Hi,

    I have a weird behaviour with hibernate.

    Inserts are working fine, but updates are stange.
    I update an object, flush it via hibernate.
    If I check the database, the changes are made.

    Then when I check the result on my browser, I get the new data. But if I refresh several times, sometimes I get the old data.

    i am using hibernate version 3.0

    My HibernateUtil

    import net.sf.hibernate.HibernateException;
    import net.sf.hibernate.Session;
    import net.sf.hibernate.SessionFactory;
    import net.sf.hibernate.cfg.Configuration;

    public class HibernateUtil {

    //private static Log log = LogFactory.getLog(HibernateUtil.class);

    private static final SessionFactory sessionFactory;

    static {
    try {
    // Create the SessionFactory
    //sessionFactory = new Configuration().configure().buildSessionFactory();
    sessionFactory = new Configuration().configure(“/hibernateJobMySql.cfg.xml”).buildSessionFactory();
    } catch (Throwable ex) {
    //log.error(“Initial SessionFactory creation failed.”, ex);
    throw new ExceptionInInitializerError(ex);
    }
    }

    public static final ThreadLocal session = new ThreadLocal();

    public static Session currentSession() throws HibernateException {
    Session s = (Session) session.get();
    // Open a new Session, if this Thread has none yet
    if (s == null) {
    s = sessionFactory.openSession();
    session.set(s);
    }
    return s;
    }

    }

    The Save() of my object :

    public void save() throws HibernateException, SQLException {
    Session session = HibernateUtil.currentSession();
    session.save(this);
    session.flush();
    }

    Any Idea why this is happening?

    Please reply soon

    #234685 Reply

    slepit
    Member

    Sorry I am using MyEclipse v4 milestone 2 and hibernate 2.1

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Hibernate : getting old data though change appears in DB

You must be logged in to post in the forum log in