posted 13 years ago
I'm very new to JPA and have inherited some code which looks pretty inefficient. It's job is to cancel some cashflows in the database by updating the original cashflow's isLatestVersion flag and endDate and inserting new versions with a status of cancelled. To do this it gets all the cashflows to update and then loops through each one, cloning it, updating fields, and then calling EntityManager.persist() for the new cashflow and EntityManager.merge() for the updated cashflow. The code looks like:
Is there a way in JPA to do the inserts in one go without having to loop through each one?
Any other ways to make this more efficient? I don't think there's any transaction flags set anywhere so would doing the work inside a transaction help speed it up (I'm assuming the default is AutoCommit or something similar)?
Thanks
Willy