-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Potential bug in value returned from updateQuery?
PostPosted: Thu Dec 17, 2009 12:00 pm 
Beginner
Beginner

Joined: Thu May 28, 2009 10:25 am
Posts: 21
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.