Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] updateObject - How do I get the numbers of rows that where changed

We retrieve the row-count for UpdateObjectQuery, but do not return it
currently.  An UpdateAllQuery or DataModifyQuery returns the row-count. 
UpdateObjectQuery will however raise the SessionEvent noRowsModified if the
update did nothing, you should be able to register for this event.

You may also wish to log a bug that UpdateObjectQuery should return the
row-count.




AnaTatavu wrote:
> 
> I agree it is not recommended and not nice to blindly try to update, but
> in our case it will save a lot of lookups in the database.
> Normally,we receive lots of updates from a different product and we need
> to update our database each time.The  cases when those updates are not a
> real update , but they are new objects are very rare.
> and we cannot know in if they are or not a real update.
> Using unitOfWork will still check the object exists in the database.
> 
> By "check the row-count yourself " do you mean just count the rows in the
> table with a separate Query or 
> once the transaction is commited I can get the information? 
> 
> 
> James Sutherland wrote:
>> 
>> In general I would recommend using JPA or the UnitOfWork API, not
>> writeObject/updateObject.  Especially with a ClientSession, as UnitOfWork
>> is required with ClientSession, writeObject/updateObject should only be
>> used with a DatabaseSession.
>> 
>> Using updateObject will just do the update, if the row does not exist it
>> will just do nothing.  If you used optimistic locking in your object, the
>> row count would be 0 and EclipseLink would throw an error.  Otherwise you
>> could check the row-count yourself I suppose, but probably not a good
>> idea to try updating something that does not exist.
>> 
>> 
>> AnaTatavu wrote:
>>> 
>>> In 90% of the cases , we need to do an update not an insert.
>>> Using writeObject is causing to many db round-trips, since we are almost
>>> sure is an update , not an insert.
>>> We still need to figure out , when the update didn't occurr, so we can
>>> do an insert.
>>> At the end of the next code, I will need to know if all the updates
>>> succeeded(all the rows where found and they were updated).
>>> 
>>> 
>>>       beginTransaction(cs);
>>>                 for ( Object row : rowList )
>>>                 {
>>>                     if ( row != null )
>>>                     {
>>>                           Object query = cs.updateObject(row);
>>>                     }
>>>                 }
>>>                 commitTransaction(cs);
>>> In the eclipseLink doc is written:
>>> The updateObject method updates existing objects in the database, but
>>> does not perform the does-exist check before it attempts the update
>>> operation. The updateObject is more efficient than the writeObject
>>> method if you are certain that the object does exist in the database. If
>>> the object does not exist, the database throws an exception when you
>>> execute the updateObject method. 
>>> (from http://wiki.eclipse.org/Using_Basic_Query_API_(ELUG))
>>> I don't receive any exception in the case the object doesn't exists.
>>> 
>>> Thank you,
>>> Ana
>>> 
>>> 
>> 
>> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/updateObject---How-do-I-get-the-numbers-of-rows-that-where-changed-tp25371193p25474030.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top