EJB - Can you use a bean within a bean
For example, can I do the following
@Stateless
@LocalBean
public class MyBean extends AbstractFacade<MyBeanEntity>
{ @PersistenceContext(UnitName='myPU")
private EntityManager em;
@EJB
private MyBean2 bean2;
@EJB
private MyBean3 bean3;
....
}
For MyBean2 and MyBean3, they look like this
public class MyBean2 extends AbstractFacade<MyBean2Entity>开发者_开发百科
{ @PersistenceContext(UnitName='myPU")
private EntityManager em;
....
}
public class MyBean3 extends AbstractFacade<MyBean3Entity>
{ @PersistenceContext(UnitName='myPU")
private EntityManager em;
....
}
I need to do this because myBean need to call some business logic implemented in myBean2 and myBean3. But I am not sure if this will work or how the whole "@EJB bean injection" works in this situation. Any thoughts? Thanks alot!
Sure you should have no problem using @EJB within another EJB. Make sure you have @Local on top of your second bean class.
精彩评论