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