如何联系管理实体的实体经理。我是说; 假设我在 sessionBean 中有一个实体引用,我怎样才能得到这个实体的 entityManager 属于一个?我已经尝试过(请参阅 getEntityManagerOfEntity() 方法)包含 em 的方法;但它不起作用。
谢谢bgrds
@Stateless(name = "MainManager", mappedName = "MainManager")
@TransactionManagement(TransactionManagementType.CONTAINER)
@Interceptors(value = { PerformanceMonitor.class, ProfileInterceptor.class })
public class MainManagerBean implements MainManager, MainManagerLocal
{
private Logger logger = Logger.getLogger(this.getClass());
@PersistenceContext(unitName = "DSApp")
private EntityManager manager;
@PersistenceContext(unitName = "DSIX")
private EntityManager integrationManager;
@Resource
SessionContext ctx;
public EntityManager getEntityManagerOfEntity(SuperEntity superEntity)
{
if (manager.contains(superEntity))
return manager;
else if (integrationManager.contains(superEntity))
return integrationManager;
return null;
}
public SuperEntity findByPrimaryKey(SuperEntity superEntity)
{
getEntityManagerOfEntity(superEntity).setFlushMode(FlushModeType.COMMIT);
return dao.findByPrimaryKey(getEntityManagerOfEntity(superEntity), superEntity);