0 Replies Latest reply on Nov 6, 2006 5:17 AM by Konstantin Ermakov

    SessionContext injection

    Konstantin Ermakov Newbie


      I have the Entity Listener, and I want to inject a SessionContext into it:

      public class EntityBeanListener {
       private @Resource SessionContext context;
       void afterInsert(Object obj) {
       Queue q = (Queue) context.lookup("queue/MyOwnQueue");
       QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("ConnectionFactory");
       QueueConnection cnn = factory.createQueueConnection();
       QueueSession session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
       TextMessage msg = session.createTextMessage("Inserted");
       QueueSender sender = session.createSender(q);

      But the context is null, so I have the NullPointerException. Is there any workaround for this problem? In fact, the only thing that I need is to send a message to the message queue. Is there any other way to do it?