Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top