This discussion is archived
1 Reply Latest reply: Feb 23, 2012 8:30 AM by JamesSutherland RSS

how to use JPA in a worker thread?

858660 Newbie
Currently Being Moderated
I'm using WebLogic 10.3.5.0 with JPA 2.0 and have the following scenario:

- user needs to start a task takes some time to complete;
- this task needs to read and write to DB;

One solution would be to write a worker and use the WorkManager feature to start this from an session EJB.

How should I use JPA from this worker to access the DB in a transactional manner?
  • 1. Re: how to use JPA in a worker thread?
    JamesSutherland Pro
    Currently Being Moderated
    You should be able to use it as normal.

    Your worker class is probably not injected like your SessionBean, so you would either need to pass the EntityManager, or look it up either through JNDI if container managed, or Persistence if application managed.
    For transactions, you either need to use JTA directly if using JTA, or use JPA transactions if using RESOURCE_LOCAL.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points