Reputation: 267267
I'm trying to setup hibernate in a project, and as part of it, I'm trying to do a simple update query just to make sure that its able to work. Here's my code:
Session sess = factory.openSession();
sess.beginTransaction();
sess.createSQLQuery("UPDATE fooTable SET bar='baz' ");
sess.getTransaction().commit();
sess.close();
When I run the code, everything executes without any error messages, and I see debug messages about getting a JDBC driver (using the config info I've provided), but the update query doesn't seem to be executed, as the table still shows the old info.
What am I doing wrong?
Upvotes: 2
Views: 270
Reputation: 6408
You created the query, but didn't execute it.
...
Query qry = sess.createSQLQuery("UPDATE fooTable SET bar='baz' ");
int updatedRows = qry.executeUpdate();
...
Upvotes: 4