jsf 2 - EJB not serialized in Managed Bean -
my application server websphere application server v8. have session scoped managed bean in have injected ejb (ejb 3.0) using @ejb annotation. ejb stateless.
@managedbean @sessionscoped public class mybean extends basebackingbean implements serializable { @ejb private idetails custinfo;
i analyzing session data , noticed notserializableexception
java.io.notserializableexception: com.ejb.ejslocal0sldetailsimpl_081f812d @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1184) @ java.io.objectoutputstream.defaultwritefields(objectoutputstream.java:1537) @ java.io.objectoutputstream.writeserialdata(objectoutputstream.java:1502) @ java.io.objectoutputstream.writeordinaryobject(objectoutputstream.java:1420) @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1178) @
now tried mark ejb transient , works fine without throwing notserializableexception exception.
@ejb private transient idetails custinfo;
is correct implementation or can alternate solution?
i have referred should ejbs instance variables , marked transient in jsf managed beans? mentioned marking ejb transient not required; can wrong?
implemented poc code on v8 both local , remote interfaces, noted following:
a. local interface (ejb not implement serializable)
// initializing ejb in servlet serializabletestejblocal localsrvlt=new serializabletestejb(); //try serialize fileoutputstream objfos = new fileoutputstream("d:\\mytest\\testsrv.txt"); objectoutputstream objopstr = new objectoutputstream(objfos); objopstr.writeobject(localsrvlt);
this resulted in java.io.notserializableexception: com.ibm.test.serializabletestejb @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:.. prevent this, ejb had explicitly implement serializable.
b. remote interface (ejb not implement serializable)
//obtain remote stub. serializabletestejbremote seremotesrvlt=(serializabletestejbremote)portableremoteobject.narrow(homeobject, serializabletestejbremote.class); //try serialization fileoutputstream objfos = new fileoutputstream("d:\\mytest\\testsrv.txt"); objectoutputstream objopstr = new objectoutputstream(objfos); objopstr.writeobject(seremotesrvlt);
the serialization successfully.
conclusion:
the inherent mechanism of remote interface obtain stub or proxy allow client-server communication occurs using proxy pattern. involves marshalling , unmarshalling of data , hence proxy-stub serializable default , hence ejb not need implement serializable interface.
but local interfaces not involve remote ups , stub handlers. ejb initializes similar initializing locally available class, hence serialization not available default. in scenario, either ejb need implement serializable interface or object need declared transient skip serialization.
i declaring variable transient. might websphere specific solution
Comments
Post a Comment