在不同的EJB中获取和处理实体Bean

问题描述 投票:0回答:1

我开发和使用JPA和无状态EJB的应用程序。基本上,该应用程序包括负责实现业务案例的EJB和负责从底层数据库中获取和删除数据的EJB。

示例:

public interface UserContextAccessEJBLocal {

 /**
  * Persists the passed instance of {@link UserContex}.
  * 
  * @param userContext an instance of {@link UserContext}
  * @throws NullPointerException if userContext is null. 
  * @throws IOException if an I/O related error occurs.
  */
 void remove(UserContext userContext)
            throws IOException;}

[我的问题:如果在EJB A中获取了JPA实体并传递给EJB B,我可以假定传递的实例属于注入到B中的EntityManager管理的持久性上下文,还是我必须提取其实例? ID有提要吗?

关于我的问题,无状态EJB和有状态EJB之间有区别吗?

ejb-3.0 java-ee-7 jpa-2.1
1个回答
0
投票

您应该避免在不同事务之间传递实体,但是只要在调用与加载实体的调用属于同一事务的一部分中发生,在EJB之间传递实体就不成问题。

© www.soinside.com 2019 - 2024. All rights reserved.