1

JNDI查找在我的EJB項目中,我有這個會話Bean(有狀態):EJB - 序列化錯誤,而這樣做的有狀態會話bean

@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); 
    } 

} 

接口StatefulShopCartLocal:

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

當我在Application Client Project中查找:

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

我收到此錯誤:

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) 

... 

我認爲這是會話bean的序列化問題,但是我做錯了什麼?

謝謝。

+0

直接注入的EJB BTW:爲什麼你實現Serializable? – Cris

+0

僅在方法級別處理:如果在遠程業務接口中公開方法使返回和參數類型實現Serializable接口 – Cris

+0

不要使用瞬變 – Cris

回答

0

我對你怎麼能在這裏訪問會話bean的一個樣本:從遠程客戶端,並從當地一個

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

對於你不再需要初始上下文相同的應用程序服務器上的本地接入,可以通過@EJB

+0

我欣賞你的幫助,但我的問題是,當在Application Client項目中執行第一次查找時,在方法void main中,我得到上述錯誤: – Emanuel

+0

java.rmi.MarshalException:CORBA BAD_PARAM 1330446342 Maybe;嵌套的異常是:java.io.NotSerializableException:... – Emanuel

+0

是刪除可序列化的...因爲在這裏容器處理,然後在應用程序客戶端中,您可以通過@EJB註釋注入應用程序客戶端中的bean,因爲在相同的VM – Cris

相關問題