Is it okay to pass injected EntityManagers to EJB bean's helper classes and use it?

后端 未结 3 1092
梦毁少年i
梦毁少年i 2020-12-29 01:02

We have some JavaEE5 stateless EJB bean that passes the injected EntityManager to its helpers.

Is this safe? It has worked well until now, but I found out some Ora

3条回答
  •  时光说笑
    2020-12-29 01:22

    Well, personally, I wouldn't like to have to pass the Entity Manager to all my POJOs in my constructors or methods. Especially for non-trivial programs where the number of POJOs is large.

    I would try to create POJOs/HelperClasses that deal with the Entities returned by the EntityManager, instead of using the entitymanager directly.

    If not possible, I guess I'd create a New EJB Bean.

提交回复
热议问题