1 Reply Latest reply on Feb 23, 2012 4:30 PM by james_sutherland

    how to use JPA in a worker thread?

    Bogdan Stroe-Oracle
      I'm using WebLogic 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?
          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.