EJB - Serialization error while doing a JNDI lookup for a Stateful Session Bean

1.7k views Asked by At

In my EJB project I have this Session Bean (Stateful):

@Stateful
public class StatefulShopCart implements StatefulShopCartLocal, Serializable {

    private static final long serialVersionUID = 1L;

    private transient HashMap<Integer, Integer> cantitati;
    private Vector<ProdusDTO> produse;

    /**
     * Default constructor. 
     */
    public StatefulShopCart() {
        try{
            cantitati = new HashMap<Integer, Integer>();
            produse = new Vector<ProdusDTO>();
        }catch(Exception ex) {
            System.out.println("[[[ //// Error \\\\ ]]]: "+ex.getMessage());
            System.out.println(ex.getStackTrace());
        }
    }

    @Override
    public void Adauga(int id) {
        try {
            InitialContext ctx = new InitialContext();
            StatelessInterogareRemote bean = (StatelessInterogareRemote) ctx
                .lookup("java:global/ShopEAP/ShopEJB/StatelessInterogare");
                    ...
        }catch(Exception ex) {
            System.out.println("[[[ Error ]]]: "+ex.getMessage());
            System.out.println(ex.getStackTrace());
        }
    }

    @Override
    public Vector<ProdusDTO> ProduseAdaugate() {
        return produse;
    }

    //@Override
    public HashMap<Integer, Integer> CantitatiProduse() {
        return cantitati;
    }

    @Override
    public double ValoareTotala() {
        StatelessCartLocal beanCart = null;
        try {
            InitialContext ctx = new InitialContext();
            beanCart = (StatelessCartLocal) ctx
                .lookup("java:global/ShopEAP/ShopEJB/StatelessCart");
        }catch(Exception ex) {
            System.out.println("+++ Error +++ " + ex.getMessage() + "\r\n" + ex.getStackTrace());
        }
        return beanCart.Calculeaza(produse, cantitati);
    }

}

The interface StatefulShopCartLocal:

@Local
public interface StatefulShopCartLocal {
    void Adauga(int id);
    Vector<ProdusDTO> ProduseAdaugate();
    HashMap<Integer, Integer> CantitatiProduse();
    double ValoareTotala();
}

When I do a lookup in Application Client Project:

InitialContext ctx = new InitialContext();
beanCart = (StatelessCartLocal) ctx
    .lookup("java:global/ShopEAP/ShopEJB/StatelessCart");

I get this error:

Nov 1, 2011 1:15:46 PM com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
Nov 1, 2011 1:15:47 PM com.sun.enterprise.naming.impl.SerialContext lookup
SEVERE: enterprise_naming.serialctx_communication_exception
Nov 1, 2011 1:15:47 PM com.sun.enterprise.naming.impl.SerialContext lookup
SEVERE: 
java.rmi.MarshalException: CORBA BAD_PARAM 1330446342 Maybe; nested exception is: 
    java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM:   vmcid: OMG  minor code: 6 completed: Maybe
    at com.sun.corba.ee.impl.logging.OMGSystemException.notSerializable(OMGSystemException.java:990)
    at com.sun.corba.ee.impl.logging.OMGSystemException.notSerializable(OMGSystemException.java:1005)
    at com.sun.corba.ee.impl.orbutil.ORBUtility.throwNotSerializableForCorba(ORBUtility.java:753)
    at com.sun.corba.ee.impl.encoding.CDROutputStream_1_0.write_abstract_interface(CDROutputStream_1_0.java:765)
    at com.sun.corba.ee.impl.encoding.CDROutputObject.write_abstract_interface(CDROutputObject.java:709)

...

at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at Main.runTest(Main.java:49)
    at Main.main(Main.java:17)
Caused by: java.io.NotSerializableException: ----------BEGIN server-side stack trace----------
org.omg.CORBA.BAD_PARAM:   vmcid: OMG  minor code: 6 completed: Maybe
    at com.sun.corba.ee.impl.logging.OMGSystemException.notSerializable(OMGSystemException.java:990)
    at com.sun.corba.ee.impl.logging.OMGSystemException.notSerializable(OMGSystemException.java:1005)

...

I think it is a problem with the serialization of that session bean, but what I am doing wrong?

Thanks.

1

There are 1 answers

3
Cris On

I have a sample of how you can access a session bean here :

http://javastuff.info/?p=110

from a remote client and from a local one.

For local access on the same application server you don't need anymore initial context ,you can inject directly the ejb via @EJB