Reputation: 1597
I need to update thousands of Entities and the logic can not be put into a SQL statement. When using non-managed JPA the pattern I use is:
long commitThreshold = 100; // or other appropriate value
try {
em.beginTransction().begin();
for(list of entities to be modified) {
// retrieve current Entity
// modify current Entity
if((++modifiedEntityCount % commitThreshold) == 0) {
em.getTransaction().commit();
em.getTransaction().begin();
}
}
if(em.getTransaction().isActive()) {
em.getTransaction().commit();
}
catch () {
}
finally {
// cleanup
}
In a managed environment this results in a
java.lang.IllegalStateException: Transaction management is not available for container managed EntityManagers.
What is a good pattern for this type of use case when using container managed transactions and blueprint? My specific environment is karaf 3.0.5 and openJPA 2.3.x if it matters.
Upvotes: 2
Views: 494
Reputation: 4316
Update your persistence.xml configuration to use statement batching
Upvotes: 2