Hibernate version:2.1.8
Hi, I'm having problems with this code:
1. Begin Transaction
2. Update some record using Session.update()
3. Get the JDBC Connection using Session.connection()
3.1 Declare a PreparedStatement that updates the same record.
3.2 statement.executeUpdate().
4. Commit the transaction.
The result I'm expecting, is to find the record updated according to step 3, but I find it updated according to step 2!
When I comment out step 2 and run the same test, it executes fine, but it seems that, when I add some session.update(), hibernate ignores step 3.
Code between sessionFactory.openSession() and session.close():
Code:
try {
HibernateUtil.beginTransaction();
// Retrieves the object to update (A with id=1):
AObj a = session.load(AObj.class, new Long(2));
// retrieves B object (id=31) and sets it on A:
a.setB(session.load(BObj.class, new Long(31)));
session.update(estado);
log.debug("Record updated using hibernate!");
// Obtains the JDBC Connection:
Connection conn = HibernateUtil.getSession().connection();
String sql = "update A_TABLE " +
"set B_id = ? " +
"where id = ? ";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, new Long(57).longValue());
pstmt.setLong(2, new Long(1).longValue());
// tries to set BObj (id=57) on A (id=2).
pstmt.executeUpdate();
log.debug("Record updated using JDBC!");
HibernateUtil.commitTransaction();
} catch (Exception e) {
HibernateUtil.rollbackTransaction();
} finally {
HibernateUtil.closeSession();
}
Name and version of the database you are using:Oracle 9i