Hello!
I have the Entity Listener, and I want to inject a SessionContext into it:
public class EntityBeanListener {
private @Resource SessionContext context;
...
@PostPersist
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);
sender.send(msg);
};
.....
};
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?
Thanks,
Konstantin