Do Jobs Make Common EntityManager - Play It! Framework

Let's say I have three jobs currently, two of which are identical ... like this:

CrawlJob job1 = new CrawlJob();
CrawlJob job2 = new CrawlJob();
CurrentJob job3 = new CurrentJob();


If I do the following in job1:



Will this also separate all the objects that handle job2 and job3? Sense, if I pass a model object / object to job2 / job3 that I was looking for in the database, can job2 / job3 get aborted because the object will just be disconnected from the session?

Likewise, let's say I do the following in job1:

long id = 123
User user1 = new User(id);;


And then in job2 or job3 I do:

User user2 = User.findById(id);


will user2 be "null" or "user1"? Meaning, although user1 hasn't been cleared / tied to the database yet, will job2 or job3 be able to search for it using the Id?

I think both of these questions are about whether Jobs (regardless of whether they are instances of the same job or a different job) share the EntityManager and therefore .em (). flush (),. em (). clear () or .em (). getTransaction (). commit () OR () will affect all jobs at the same time?


source to share

1 answer

Starts its own jpa transaction and your entities don't actually persist until the transaction completes.

Thus, job2 will not see the changes made by job1 unless job 1 completes when job2 loads the object.

If you want to commit data while jobs1 are running, you can commit the transaction on job1 and start a new one with something like:





All Articles