3 Replies Latest reply on Jan 17, 2008 1:35 PM by Pete Muir

    Can I inject a session bean into a stateless session bean?

    Gus Gu Expert

      Hi,

      I am not sure whether I can inject a session bean (e.g. currentUser) into a stateless session bean, and each user will have his owner username in the stateless session bean when he/she call it. For example:

      @Stateless
      @Name("friend")
      public class FriendAction implements Friend {
      
       @In
       private Person user;
      
       @Out
       private List <Person> friends;
      
       @PersistenceContext
       private EntityManager em;
      
       public void retrievFriends () {
       friends = em.createQuery("select pf.friend from PersonFriend pf where pf.person.id=:userId")
       .setParameter("userId", user.id());
       .getResultList();
       }
      
      }
      Thank you.