-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Get after save returns MySQL TIMESTAMP field, otherwise not
PostPosted: Fri Feb 25, 2005 6:06 pm 
Newbie

Joined: Wed Feb 16, 2005 10:46 am
Posts: 13
Location: Lake Worth, FL
I am using Hibernate 2.1.8 on JBoss 4.0.1

I am trying to avoid a round trip through Hibernate by returning the POJO ref after a save instead of just the id with a save and then the POJO ref with a get. This was a pattern I had developed while working with DTOs for the transfer to/from the session facade.

So after making this in my create method, I noticed all was not the same.

I have an UPDATED field defined in MySql as TIMESTAMP such that the current time is always updated when the record is changed.

I have noticed the following:

When I did a round-trip this field is set. All was working fine. Then I decided to eliminate the get of the POJO after the save because the save should have synchronized the object with the DB and indeed it does EXCEPT for this TIMESTAMP field which is null.

I threw an hsession.flush() in there and was still out of synch on ONLY this TIMESTAMP field.

The new code looks like this (with the try/catches removed)

Code:
   public Branch createBranch(Branch branch)
      throws HibernateException {
       Session        hsession = _sessionFactory.openSession();
      Transaction tx = hsession.beginTransaction();
      TouchTagUtil.create(_ctx, branch);
       hsession.save(branch);
       tx.commit();
       hsession.flush();
       hsession.close();
       return branch;
   }   


while the old code looked like this (with try/catches removed)

Code:
   public String createBranch(Branch branch)
      throws HibernateException {
       Session        hsession = _sessionFactory.openSession();
      Transaction tx = hsession.beginTransaction();
      TouchTagUtil.create(_ctx, branch);
       hsession.save(branch);
       tx.commit();
       hsession.flush();
       hsession.close();
       return branch.getId();
   }   
   
   public Branch getBranch(String id)
      throws HibernateException {
       Session        hsession = _sessionFactory.openSession();
      Transaction tx = hsession.beginTransaction();      
       Branch b = (Branch) hsession.load(Branch.class, id);
       tx.commit();         
       hsession.close();
       return b;
   }
   


Can anyone suggest an explanation as to why this would be?

Many thanks,
Joe


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.