abhi
abhi

Reputation: 1756

Hibernate's SQLQuery executeUpdate function starts, but does not fully execute

Working on a Spring application that uses Hibernate, and in my DAO layer we are running an UPDATE statement to update some values in an Oracle database.

To make sure I'm not crazy, I ran the statement in SQL Developer to make sure it works properly. Here is part of my DAO code:

public void updateObjectInMyTable(SomeClassA objectOfSomeClassA) {
        Session session = getCurrentSession();
        String sql = "UPDATE SCHEMA_NAME.TABLE_XYZ SET FIRST_NAME=:firstName, LAST_NAME=:lastName, ADDRESS=:address, CITY=:city, ZIPCODE=:zipcode WHERE ID_NUMBER = :idNumber";
        SQLQuery query = session.createSQLQuery(sql);
        query.setParameter("firstName", objectOfSomeClassA.getFirstName());
        query.setParameter("lastName", objectOfSomeClassA.getLastName());
        query.setParameter("address", objectOfSomeClassA.getAddress());
        query.setParameter("city", objectOfSomeClassA.getCity());
        query.setParameter("zipcode", objectOfSomeClassA.getZipcode());
        query.setParameter("idNumber", objectOfSomeClassA.getIdNumber());
        query.executeUpdate();
    }

(Excuse the poor variables names used for substitutions of the real ones.) I did debug on the server and I do not see any errors with query.executeUpdate() It gets to that line, and doesn't pass on to the next statement I have in my service layer.

Anything I'm doing wrong?

Upvotes: 0

Views: 1467

Answers (1)

Mohammadreza Khatami
Mohammadreza Khatami

Reputation: 1332

Where's your transaction ?!

Use :

session.beginTransaction().commit();

add this in the end line of your code.

I hope this helps you.

Upvotes: 1

Related Questions