users@glassfish.java.net

InitialContext.lookup works but _at_Resource does not

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Thu, 11 Feb 2010 16:41:41 +0100

Hi there,
I have problem in one of my session bean deployed on Glassfish v2.1.1.
The bean is supposed to send messages to WebSphere MQ using WebSphere
MQ JCA Adapter. So, in order to send a message it needs two objects:
ConnectionFactory and Queue.
When I look for those objects using InitialContext, everything works
and messages are sent.

The code below works:
----------------------------------------
ConnectionFactory ivtcf = null;
Queue ivtQueue = null;
try {
    InitialContext ctx = new InitialContext();
    ivtcf = (ConnectionFactory) ctx.lookup("jms/IVTCF");
    ivtQueue = (Queue) ctx.lookup("jms/IVTQueue");
} catch (NamingException ex) {
    throw new RuntimeException(ex);
}

logger.info("ivctf="+ivtcf);
logger.info("ivtQueue="+ivtQueue);
----------------------------------------


The problem is I cannot use @Resource injection to get rod of those
InitialContext lookups and NamingExceptions:
----------------------------------------
@Resource(mappedName = "jms/IVTCF")
private ConnectionFactory ivtcf;
@Resource(mappedName = "jms/IVTQueue")
private Queue ivtQueue;
----------------------------------------

The above declarations cause exceptions when container tries to create
that session bean:
(bean name is wmqtest.Producer, full stacktrace in attachment)

NAM0002: Exception in NamingManagerImpl copyMutableObject().
java.io.NotSerializableException: java.lang.Object
[...]
EJB5070: Exception creating stateless session bean : [{0}]
com.sun.enterprise.InjectionException: Exception attempting to inject
Res-Ref-Env-Property:
wmqtest.Producer/ivtcf_at_javax.jms.ConnectionFactory@ resolved as: jndi:
jms/IVTCF_at_res principal: null_at_mail: null
No Runtime properties
Database Vendor : null
Create Tables at Deploy : false
Delete Tables at Undeploy : false into class wmqtest.Producer
[...]
Caused by: javax.naming.NameNotFoundException: No object bound for
java:comp/env/wmqtest.Producer/ivtcf [Root exception is
java.lang.RuntimeException: Cant copy Serializable object:]
[...]
nested exception is: javax.ejb.EJBException: nested exception is:
javax.ejb.CreateException: Could not create stateless EJB


Can you tell me what is wrong with all this? Could it be a bug in
Glassfish or WebSphere MQ JCA Adapter?
I am attaching the entire log, the source code of my session bean and
domain.xml.

Thanks,
Witold Szczerba