Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Is it possible to do batch updates using EclipseLink/JPA?

You can use batch writing using the persistence.xml property,

"eclipselink.jdbc.batch-writing"="JDBC"

See,
http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/config/PersistenceUnitProperties.html#BATCH_WRITING

The merge() API must read the object from the database if it does not exist
in the cache.  If you do not want it to read from the database, ensure you
have caching enabled (it is by default), or perhaps increase you cache size
or type.  You must read an object before updating it, as otherwise you do
not know what changed, or what related objects changed.

EclipseLink will always compute what fields changed, whether using weaving
or not.  Weaving just allows the changes to be tracked through events,
instead of through backup copies.



shkolnik wrote:
> 
> I have a very simple requirement: update a large number of records in DB. 
> Using plain JDBC it would look like this: 
> PreparedStatement stmt = connection.prepareStatement("update person set
> age = ? where id = ?"); 
> String age = getAge(); 
> for(Person p : people) { 
>      stmt.setString(1, age); 
>      stmt.setLong(2, p.getId()); 
>      stmt.addBatch(); 
> } 
> stmt.executeUpdate(); 
> 
> Using EclipseLink, I get the same effect like this: 
> 
> for(Person p : people) { 
>      p = unitOfWork.registerExistingObject(p); 
>      p.setAge(age); 
> } 
> unitOfWork.commit(); 
> 
> My question: is it possible to implement this using only JPA interfaces? I
> tried using EntityManager.merge(), but it always executes a select
> statement to check if record exists in db. I tried adding
> @ExistenceChecking(value = ExistenceType.ASSUME_EXISTENCE) to the entity,
> but it doesn't help. The second part of the question is even if its
> possible to somehow force JPA not to check database, is it possible to
> implement change tracking without any kind of weaving or will it update
> all the fields? Maybe it's possible to specify which fields I want to be
> updated? 
> 
> Thank you for your help.
> 


-----
---
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/Is-it-possible-to-do-batch-updates-using-EclipseLink-JPA--tp22833966p22848347.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top