2012-01-13 14 views
3

私はステートフルなEJB Beanを持っています。2つのネストされたEJB Bean - 最初にEntity Managerを注入します。

ステートフルBeanはエンティティマネージャ(注入)を使用し、シングルトンBeanを呼び出します。 シングルトンのBeanはエンティティマネージャ(注入)を使用します。

シングルトンBeanをステートフルBeanからコールしようとすると、シングルトンBeanはEntity Managerをインジェクションしません。

両方のBeanでエンティティマネージャを同時に取得することはできませんか?

EJBビーン

@Singleton 
@LocalBean 
public class AllocationPlanController implements AllocationPlanControllerRemote { 

@PersistenceContext 
private EntityManager em; 

EJBビーン2

@Stateful 
@LocalBean 
public class AllocationController implements AllocationControllerRemote { 

@PersistenceContext 
private EntityManager em; 

private Allocation allocation; 
private AllocationPlan allocationPlan; 

AllocationPlanController allocationPlanController = new AllocationPlanController(); 
+0

いくつかのコードを投稿できますか?たぶん、豆を注入して呼び出す方法を見てみましょう。もう少し明確にするのに役立つものがあります – jere

+0

いくつかのコードが役に立ちます – Eugene

答えて

3

あなたが "手動"、それのコンストラクタでAllocationPlanControllerインスタンスを作成しているので、EntityManagerAllocationPlanControllerに注入されていません。 AllocationPlanControllerAllocationController beanに挿入し、コンテナのライフサイクルを管理させる必要があります。

0

代わりに、そのコンストラクタを介して新しいAllocationPlanControllerを作成するので、同じように注釈を付けてみてください。

@EJB 
AllocationPlanController allocationPlanController; 

その後、コンテナはあなたのAllocationControllerにそのBeanを注入しますと、コンテナは、それが作成したBeanを注入しますから、それはすでにdepenedenciesを注入しているので、emのためのnullでない値を見つけるでしょう。