hainp
hainp

Reputation: 11

javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB

I have found some same-title articles . Unfortunately, I couldn't find any solution for my error.

I'm new to JEE, JSF, EJB. I'm using Netbeans 7.0.1. I'm following this guide: http://wiki.netbeans.org/DevelopJavaEE6App.

This is: CustomerSessionBean:

@Stateless
@LocalBean
public class CustomerSessionBean {

@PersistenceContext
private EntityManager em;
@Resource(name = "jms/NotificationQueue")
private Queue notificationQueue;
@Resource(name = "jms/NotificationQueueFactory")
private ConnectionFactory notificationQueueFactory;

public List<Customer> retrieve() {
    Query query = em.createNamedQuery("Customer.findAll");
    return query.getResultList();
}

public Customer update(Customer customer) {
    Customer updated = em.merge(customer);
    try {
        sendJMSMessageToNotificationQueue(updated);
    } catch (JMSException ex) {
        Logger.getLogger(CustomerSessionBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println("Customer updated in CustomerSessionBean!");
    return updated;
}

private Message createJMSMessageForjmsNotificationQueue(Session session, Object messageData) throws JMSException {

    ObjectMessage tm = session.createObjectMessage();
    tm.setObject((Serializable) messageData);
    return tm;
}

private void sendJMSMessageToNotificationQueue(Object messageData) throws JMSException {
    Connection connection = null;
    Session session = null;
    try {
        connection = notificationQueueFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer messageProducer = session.createProducer(notificationQueue);
        messageProducer.send(createJMSMessageForjmsNotificationQueue(session, messageData));
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (JMSException e) {
                Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close session", e);
            }
        }
        if (connection != null) {
            connection.close();
        }
    }
}

public List<DiscountCode> getDiscountCodes() {
    Query q = em.createNamedQuery("DiscountCode.findAll");
    return q.getResultList();
}
}

I get this error: "javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB" every time I access a jsf page (In the guide: CustomerList.jsp; CustomerDetails.jsp) if I don't comment the "@Resource(name = "jms/NotificationQueue")". If I comment it, jsf page will display.

EDIT: this is stack trace:

javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2528)
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1895)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy226.retrieve(Unknown Source)
at com.customerapp.ejb.__EJB31_Generated__CustomerSessionBean__Intf____Bean__.retrieve(Unknown Source)
at com.customerapp.web.CustomerMBean.getCustomers(CustomerMBean.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:55)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:55)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at javax.faces.component.UIData.getDataModel(UIData.java:1798)
at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484)
at javax.faces.component.UIData.setRowIndex(UIData.java:473)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:820)
at javax.faces.component.UIData.encodeBegin(UIData.java:1118)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1754)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(JspViewHandlingStrategy.java:432)
at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:233)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:726)
at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:247)
at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:449)
... 70 more
Caused by: javax.ejb.CreateException: Could not create stateless EJB
at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:534)
at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:95)
at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:724)
... 72 more
Caused by: java.lang.IllegalStateException: Exception attempting to inject Unresolved Message-Destination-Ref jms/[email protected]@null into class com.customerapp.ejb.CustomerSessionBean: Lookup failed for 'java:comp/env/jms/NotificationQueue' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:137)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:50)
at org.jboss.weld.bean.SessionBean$1.inject(SessionBean.java:190)
at org.glassfish.weld.services.JCDIServiceImpl.injectEJBInstance(JCDIServiceImpl.java:223)
at com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1675)
at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:494)
... 74 more
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Unresolved Message-Destination-Ref jms/[email protected]@null into class com.customerapp.ejb.CustomerSessionBean: Lookup failed for 'java:comp/env/jms/NotificationQueue' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:703)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:130)
... 79 more
Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/jms/NotificationQueue' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/env/jms/NotificationQueue [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
... 82 more
Caused by: javax.naming.NameNotFoundException: No object bound for java:comp/env/jms/NotificationQueue [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:242)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
... 86 more
Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.WrappedSerialContext.getURLScheme(WrappedSerialContext.java:146)
at com.sun.enterprise.naming.impl.WrappedSerialContext.getURLOrDefaultInitCtx(WrappedSerialContext.java:103)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:82)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:172)
... 87 more

Upvotes: 0

Views: 16063

Answers (2)

BeePee
BeePee

Reputation: 11

Deleting of glassfish-ejb-jar.xml and Clean&Build helps in my case (Netbeans 7.1.1, glassfish 3.1.2)

Upvotes: 1

akira
akira

Reputation: 1772

The JMS destination jms/NotificationQueue normally needs to be created. The guide indeed doesn't mention it.

Perhaps the Netbeans wizard creates it automatically for you and you haven't yet created the MDB via the wizard?

Edit:

The guide does mention it:

  • In the New Message-Driven Bean dialog, specify the EJB Name as NotificationBean and the package as "com.customerapp.mdb", click on the "Add..." button of the Project Destination option
  • In the Add Message Destination dialog, specify the Destination Name as NotificationQueue and keep the Destination Type as Queue and click OK

This lets the Wizard create a glassfish-resources.xml file, that defines the queue:

<resources>
    <admin-object-resource enabled="true" jndi-name="jms/NotificationQueue"  res-type="javax.jms.Queue"  res-adapter="jmsra">
        <property name="Name" value="PhysicalQueue"/>
    </admin-object-resource>
    <connector-connection-pool name="jms/NotificationQueueFactoryPool"  connection-definition-name="javax.jms.QueueConnectionFactory"  resource-adapter-name="jmsra"/>
    <connector-resource enabled="true" jndi-name="jms/NotificationQueueFactory" pool-name="jms/NotificationQueueFactoryPool"  />
</resources>

If you are not following the Guide to the letter and/or are not using Glassfish, you have to define this yourself (note that every Java EE implementation has a different syntax for this).

Upvotes: 1

Related Questions