1 Reply Latest reply on Jul 4, 2014 10:02 AM by wdfink

    Problems with using a stateful session bean from a singleton bean

    danielyt

      I'm having some problems with the order application (http://docs.oracle.com/javaee/6/tutorial/doc/giqst.html) from the Java EE 6 tutorial. I don't want to include all the source code because it's too big, but you can find it online (https://svn.java.net/svn/javaeetutorial~svn/branches/javaee-tutorial-6/examples/persistence/order/).

       

       

      I'm trying to run the application on JBoss AS 7.1.1.Final. I've got JBoss tools installed on my Eclipse and I created a new Java EE Web Project and imported all the source files of the application without any changes.

       

       

      The application contains a ConfigBean (https://svn.java.net/svn/javaeetutorial~svn/branches/javaee-tutorial-6/examples/persistence/order/src/java/order/ejb/Con…), which is singleton and should be executed at deployment to fill the database:

       

       

          @Singleton

          @Startup

          public class ConfigBean {

              @EJB

              private RequestBean request;

       

       

              @PostConstruct

              public void createData() {

              ...

              }

          }

       

       

      RequestBean (https://svn.java.net/svn/javaeetutorial~svn/branches/javaee-tutorial-6/examples/persistence/order/src/java/order/ejb/Req…) is a stateful bean, containing the business logic of the application:

       

       

          @Stateful

          public class RequestBean {

              private static final Logger logger = Logger.getLogger(

                      "order.ejb.RequestBean");

              @PersistenceContext

              private EntityManager em;

              ...

          }

       

       

      When deploying the application, the database gets filled with data to a certain point and then fails at:

       

       

          public class ConfigBean {

             ...

             public void createData() {

                 ...

                 request.createVendorPart("1234-5678-01", 1, "PART1", 100.00, 100);

                 ...

             }

          }

       

       

      More precisely at:

       

       

          public class RequestBean {

          ...

              public void createVendorPart(String partNumber, int revision, String description, double price, int vendorId) {

              ...

              vendor.addVendorPart(vendorPart);

              ...

              }

          }

       

       

      I get the exception javax.ejb.EJBTransactionRolledbackException:

       

       

          ERROR [org.jboss.as.ejb3.tx.CMTTxInterceptor] (MSC service thread 1-1) javax.ejb.EJBTransactionRolledbackException

          ERROR [org.jboss.ejb3.invocation] (MSC service thread 1-1) JBAS014134: EJB Invocation failed on component RequestBean for method public void com.csc.order.ejb.RequestBean.createVendorPart(java.lang.String,int,java.lang.String,double,int): javax.ejb.EJBTransactionRolledbackException

          ...

          INFO  [org.jboss.as.ejb3] (MSC service thread 1-1) JBAS014101: Failed to find SFSB instance with session ID {[-22, 51, -128, 58, -54, -49, 68, -19, -121, 114, 73, -12, -107, -83, -126, -21]} in cache

       

       

      When I remove the @Singleton annotation from the ConfigBean class, the application deploys fine, but the database is empty.