I’m running a Job in Play! that takes a while (more than 1 hour). During this job, I want to save some id’s to my MySQL database. However, after writing the data, if I query the database in my terminal (using the MySQL monitor), the rows don’t seem to be updated. So.. I need to update this data while the job is running.
This is the code:
this.ga.lastUID = msgnums[i-1];
this.ga.count = count[i-1];
this.ga.merge();
where this.ga is the instance of my JPA model.
If I use the save() method, I get a detached exception. If I use the findById(this.ga.id) method to get a new object, I can use save() but it has the same result as merge() (i.e. nothing is updated). Anyone has an idea how to fix this?
Thanks!
A job execution is transactional. Everything you do in your job will be commited at the end of the job.
To achieve what you want you can create a subjob class an call it in the main one.
Something like
And in your main job you call
Your subjob will execute the save in another transaction that will be commited at the end of the subjob.
Be careful, we this way of work you can’t rollback all the main job