Does it make sense to have static methods in stateless ejbs?

痴心易碎 提交于 2019-12-23 19:09:56

问题


Stateles ejbs are intended to be idempotent and have no memory of previous user interactions. That sounds like a static method to me.

so instead of having

 public void save(Entity e) { em.persist(e); }

is it safe to have

 public static void save(Entity e) { em.persist(e); }

inside an EJB?


回答1:


No, because static methods do not participate in container-managed transactions, AOP, security, etc. BTW your second example won't compile, em is injected by the application server and it can't be static (?)

Also there is no such requirement that stateless EJBs should be idempotent and have no state (despite the name). Not to mention that once you start using static methods, you don't need EJBs at all...



来源:https://stackoverflow.com/questions/13202091/does-it-make-sense-to-have-static-methods-in-stateless-ejbs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!