[jboss-user] [EJB 3.0 Users] - Stateful session beans don't keep state !!!

daziplqa do-not-reply at jboss.com
Wed Oct 7 21:46:01 EDT 2009


Hi folks,

I am new to EJB and statefull sessin beans on JBoss4.2 AS
I have the following urgent problem:


I have the following statefull session bean.

  | @Stateful
  | public class PlaceOrderBean implements PlaceOrder {
  |         private ShippingInfo shippingInfo;
  | 	private BillingInfo billingInfo;
  | 
  |         public void setShippingInfo(ShippingInfo shippingInfo) {
  | 		System.out.println("Call # :  1 " );
  | 		this.shippingInfo = shippingInfo;
  | 	}
  | 
  | 	public void setBillingInfo(BillingInfo billingInfo) {
  | 		System.out.println("Call # :  2 " );
  | 		this.billingInfo = billingInfo;
  | 		System.out.println(shippingInfo.getShippingInfo());  // << NullPointerException here !!!!! how come ??!!
  | 	}
  | }
  | 
The client :

  | // this class is a JSF managed bean that is used with 2 JSPs, each one of the two calles on of the below methods
  | public class OrderItemBean {
  | 	private PlaceOrder placeOrder;
  | 
  |         public OrderItemBean() {
  | 		try {
  | 			logger.info("Getting PlaceOrder instance ...");
  | 			InitialContext ctx = new InitialContext();
  | 			placeOrder = (PlaceOrder) ctx.lookup("chapter2/" + PlaceOrderBean.class.getSimpleName() + "/local");
  | 		}catch(NamingException ex) {
  | 			ex.printStackTrace();
  | 		}
  | 	}
  |         // Note, the class OrderItemBean get instantiated a new instance before calling the following method
  |         // so, the JNDI code in the constructor above is being called to lookup the statefull bean
  |         public String setShippingInfo() {
  | 		ShippingInfo shipInfo = new ShippingInfo();
  | 		shipInfo.setShippingInfo(getShippingInfoTxt().getValue().toString());
  | 		placeOrder.setShippingInfo(shipInfo);
  | 		
  | 		System.out.println("shipping Info : " + shipInfo.getShippingInfo());
  | 		
  | 		return SUCCESS + "_setShippingInfo";
  | 	}
  |         // Note, the class OrderItemBean get instantiated a new instance before calling the following method	
  |         // so, the JNDI code in the constructor above is being called again to lookup the statefull bean
  | 	public String setBillingInfo() {
  | 		BillingInfo billingInfo = new BillingInfo();
  | 		billingInfo.setBillingInfo(getBillingInfoTxt().getValue().toString());
  | 		placeOrder.setBillingInfo(billingInfo);
  | 		
  | 		setAdditionalInfo();
  | 		
  | 		return SUCCESS + "_setBillingInfo";
  | 	}
  | 
  | }

The code above get this exception

03:06:35,264 INFO  [OrderItemBean] Getting PlaceOrder instance ...
  | 03:06:35,274 INFO  [STDOUT] Call # :  1 
  | 03:06:35,274 INFO  [STDOUT] shipping Info : Cairo, Egypt, Elobour city
  | 03:06:36,919 INFO  [OrderItemBean] Getting PlaceOrder instance ...
  | 03:06:36,929 INFO  [STDOUT] Call # :  2 
  | 03:06:36,930 FATAL [application] javax.ejb.EJBException: java.lang.NullPointerException
  | javax.faces.el.EvaluationException: javax.ejb.EJBException: java.lang.NullPointerException
  | 	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
  | 	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
  | 	at javax.faces.component.UICommand.broadcast(UICommand.java:383)
  | 	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)
  | 	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
  | 	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
  | 	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
  | 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
  | 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
  | 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
  | 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  | 	at java.lang.Thread.run(Thread.java:619)
  | 
  | .............
  | ..............
  | 

How this come, Ain't it as stateFULL session bean !!!!!!

Please Help

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4259263#4259263

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4259263



More information about the jboss-user mailing list