2 Replies Latest reply on Jul 31, 2008 6:29 PM by Bogdan Minciu

    Difference between @In and Contexts.getConversationContext().get()

    Bogdan Minciu Newbie

      Hello guys,

      I have to use this proxy class in order to avoid concurrent calls exception (http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/ejb_tier/qanda/#prevent):

      public class CommentDAOImpl {
          private LocalCommentDAO commentDAO;
          public CommentDAOImpl() {
              this.commentDAO = (LocalCommentDAO) Contexts.getConversationContext().get(CommentDAO.class);
              System.out.println("context= " + Contexts.getConversationContext());
              System.out.println("setted commentDAO= " + commentDAO);

      CommentDAO looks like this:

      public class CommentDAO implements LocalCommentDAO {

      But when I call the constructor of CommentDAOImpl, the commentDAO component is reported as null, even if the class is marked with @AutoCreate:

      14:55:18,015 INFO  [STDOUT] context= ConversationContext(3)
      14:55:18,015 INFO  [STDOUT] setted commentDAO= null

      If I use the @In annotation to inject the commentDAO component in some other stateful components, it works ok and the commentDAO component is created.

      So, what is the difference between the @In private LocalCommentDAO; annotation and the Contexts.getConversationContext().get(CommentDAO.class) calls? How can I create a component when it is injected through Contexts.getConversationContext().get(CommentDAO.class)?

      Thank you in advance,