JPA and Threads in play framework

后端 未结 4 1950
Happy的楠姐
Happy的楠姐 2021-01-11 18:07

I\'m trying to create a multithreading server. The problem is that I get the following error: play.exceptions.JPAException: The JPA context is not initialized. JPA Entit

4条回答
  •  萌比男神i
    2021-01-11 18:22

    class Runner extends Runnable {
         @Override
         public void run() {
            EntityManager em = JPA.newEntityManager();
            em.setFlushMode(FlushModeType.COMMIT);
            JPA jpa = new JPA();
            jpa.bindForCurrentThread(JPA.DEFAULT, em, false);
    
             em.getTransaction().begin();
            // ... DO YOUR STUFF HERE ...
             em.getTransaction().commit();
         }
    }
    

提交回复
热议问题