1

I have web application using hibernate for accessing database. I have an update method in DAO class, when I run this method, I get no error in console but database doesn't response, also after running the class I can not retrieve the table using sqlDeveloper. this is shown in eclipse console after running the class:

May 12, 2014 11:29:57 AM org.hibernate.engine.internal.StatisticalLoggingSessionEventListener end
INFO: Session Metrics {
    13975 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    40413377 nanoseconds spent preparing 1 JDBC statements;
    1130672 nanoseconds spent executing 1 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}

here is the update method body:

session = hu.getSessionFactory().openSession();         
Query q= session.createQuery("update MessageQueue set   returnStatus=:returnStatus where id=:msg_id");
System.out.println("QQQQQQQQQQQQQQQQQQQQQQUERY ");
q.setParameter("msg_id", id);
System.out.println("1111111111111111111111111111 param "+id);
q.setParameter("returnStatus", returnStatus);
System.out.println("222222222222222222222 param "+returnStatus);
System.out.println(q.getQueryString());
int res=q.executeUpdate();
session.close();

database is oracle.

2
  • When you say 'database doesn't response', exactly what do you mean? Does the application hang? Does the update appear to succeed but not make any change inside the database? When you say you 'can not retrieve the table', do you mean that there's an error querying the table or that the data you expect to be there isn't there? Commented May 12, 2014 at 20:54
  • I mean I don't get any response from the database! the records I try to update are locked by my user and I can not retrieve them using any tools like sql developer also.
    – AFF
    Commented May 14, 2014 at 3:34

1 Answer 1

1

it sounds to me from your comments that data isn't being committed. Try creating a transaction before doing the update and committing it afterwards:

session = hu.getSessionFactory().openSession();
Transaction transaction = session.beginTransaction();   // add this line
Query q= session.createQuery("update MessageQueue set   returnStatus=:returnStatus where id=:msg_id");
System.out.println("QQQQQQQQQQQQQQQQQQQQQQUERY ");
q.setParameter("msg_id", id);
System.out.println("1111111111111111111111111111 param "+id);
q.setParameter("returnStatus", returnStatus);
System.out.println("222222222222222222222 param "+returnStatus);
System.out.println(q.getQueryString());
int res=q.executeUpdate();
transaction.commit();                                   // add this line too
session.close();

It would also be a good idea to roll back the transaction in a catch block if any exceptions are thrown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.