简体   繁体   English

有了 JPA,是否还需要使用 EJB session bean?

[英]with JPA, is there still a need to use EJB session beans?

What are some use cases for using session beans?使用 session bean 有哪些用例? I personally prefer to hold session status in web tire when the requests need to be 'sticky". Thanks.当请求需要“粘性”时,我个人更喜欢在 web 轮胎中保持 session 状态。谢谢。

Note that some JPA concepts are tied to other JavaEE concepts and in some cases EJB.请注意,某些 JPA 概念与其他 JavaEE 概念相关联,在某些情况下还与 EJB 相关联。 Specifically, Container-Managed EntityManagers injected via @PersistenceContext具体来说,容器管理的 EntityManagers 通过@PersistenceContext注入

  • @PersistenceContext(type = EXTENDED) EntityManager em;
    • EntityManager is linked to and only usable by a @Stateful session bean EntityManager 链接到@Stateful session bean 并且只能由它使用
  • @PersistenceContext(type = TRANSACTION) EntityManager em;
    • EntityManager is linked to and only usable within the scope of the current running JTA transaction EntityManager 链接到当前运行的 JTA 事务的 scope 并且只能在其中使用

In the first case an EJB is necessary.在第一种情况下,EJB 是必需的。 In the second case, an EJB is nice to take care of the transaction plumbing automatically.在第二种情况下,EJB 很适合自动处理事务管道。

All the services provided by a session bean (declarative transactions, declarative security, asynchronous methods, timers, etc.). session bean 提供的所有服务(声明式事务、声明式安全、异步方法、计时器等)。 If you don't need any of those services, then you don't need session beans.如果您不需要任何这些服务,那么您就不需要 session 个 bean。

The main use case is to avoid having to write the tedious and verbose transaction management code that required for JPA.主要用例是避免编写 JPA 所需的繁琐冗长的事务管理代码。

With EJB this becomes nearly always invisible and at most a single extra annotation.对于 EJB,这几乎总是不可见的,最多只是一个额外的注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM