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

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-tp25371193p25388790.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top