From the java doc:
Quote:
executeUpdate
public int executeUpdate()
throws HibernateException
Description copied from interface: Query
Execute the update or delete statement. The semantics are compliant with the ejb3 Query.executeUpdate() method.
Returns:
The number of entities updated or deleted.
Throws:
HibernateException
Consider a SQL query on this table:
Code:
mysql> select * from documentreviewfolders;
+----+--------------+-------------+
| ID | attribute_ID | document_ID |
+----+--------------+-------------+
| 1 | 82 | 1 |
| 2 | 82 | 2 |
| 3 | 82 | 3 |
| 4 | 83 | 2 |
| 5 | 83 | 4 |
| 6 | 85 | 1 |
+----+--------------+-------------+
6 rows in set (0.00 sec)
mysql>
mysql>
mysql> UPDATE IGNORE documentreviewFolders SET attribute_ID = 83 WHERE attribute_ID = 82 ;
Query OK, 2 rows affected (0.06 sec)
Rows matched: 3 Changed: 2 Warnings: 0
One row was not changed because of a duplicate key condition (combination of attribute_ID and document_ID should be unique) > hence, changed rows = 2 instead of 3.
Now, executing this via a SQLQuery:
Code:
@Override
public int reassignDocuments(Session session, String tableName, long oldAttrId, long newAttrId) throws SystemFailureException {
String queryStr = "UPDATE IGNORE " + tableName + " SET attribute_ID = :newId WHERE attribute_ID = :oldId";
return session.createSQLQuery(queryStr).setParameter("newId", newAttrId)
.setParameter("oldId", oldAttrId).executeUpdate();
}
Printing the return value from this method, we have a value of 3. According to the documentation, shouldn't this be 2 i.e. shouldn't the code recognize that this was an UPDATE IGNORE, and not an UPDATE.