Getting a reference to EntityManager in Java EE applications using CDI

后端 未结 4 1494
无人及你
无人及你 2020-12-04 12:28

I\'m using Java EE 7. I would like to know what is the proper way to inject a JPA EntityManager into an application scoped CDI bean. You can\'t

4条回答
  •  佛祖请我去吃肉
    2020-12-04 13:07

    You may inject savely EntityManagerFactory, it is thread save

    @PersistenceUnit(unitName = "myUnit")
    private EntityManagerFactory entityManagerFactory;
    

    then you can retrive EntityManager from entityManagerFactory.

提交回复
热议问题