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的序列化問題,但是我做錯了什麼?
謝謝。
直接注入的EJB BTW:爲什麼你實現Serializable? – Cris
僅在方法級別處理:如果在遠程業務接口中公開方法使返回和參數類型實現Serializable接口 – Cris
不要使用瞬變 – Cris