-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem commiting with PreparedStatement.executeUpdate()
PostPosted: Mon Apr 11, 2005 6:38 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 11, 2005 6:41 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
Sorry, in the code below replace

Code:
session.update(estado);

for

Code:
session.update(a);

:P


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

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.