|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
updateObject - How do I get the numbers of rows that where changedIn 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 |
|
|
Re: updateObject - How do I get the numbers of rows that where changedIn 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.
James Sutherland EclipseLink, TopLink Wiki: EclipseLink, TopLink Forums: TopLink, EclipseLink Book: Java Persistence Blog: Java Persistence Performance |
|
|
Re: updateObject - How do I get the numbers of rows that where changed
|
|
|
Re: updateObject - How do I get the numbers of rows that where changedWe 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.
|
| Free embeddable forum powered by Nabble | Forum Help |