Skip to main content

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

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.
-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-do-batch-updates-using-EclipseLink-JPA--tp22833966p22833966.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top