[jboss-user] [EJB3] - SFSB state is not beeing maintained in jboss5.1

Santos Mandre do-not-reply at jboss.com
Fri Jun 8 03:59:52 EDT 2012


Santos Mandre [https://community.jboss.org/people/santos2178] created the discussion

"SFSB state is not beeing maintained in jboss5.1"

To view the discussion, visit: https://community.jboss.org/message/740619#740619

--------------------------------------------------------------
Hi Guys,

I am using jboss (http://www.coderanch.com/forums/f-63/JBoss) 5.1 and have written a SFSB - BillItemsListFacadBean which i am trying to invoke from a SLSB - BillFacadBean. The basic purpose of this SFSB is to store list of billitems that were selected as part of generating a document .No database calls involved in the SFSB. It has got 2 simple methods updateDeliveryMemoSelectionList and fetchDeliveryMemoSelectionList .updateDeliveryMemoSelectionList  updates the instance variable arrCummulativeDMSelectionList , which is a list and fetchDeliveryMemoSelectionList  returns this to the calling program. I am using the below code in a struts (http://www.coderanch.com/forums/f-58/Struts) action class to update the instance variable of the SFSB 
 
                         BillItemsListFacadBeanInterface billItemsListFacadBean = null; 
                try{ 
                     billItemsListFacadBean = (BillItemsListFacadBeanInterface) new InitialContext (http://docs.oracle.com/javase/7/docs/api/javax/naming/InitialContext.html)().lookup("inticraftEAR/BillItemsListFacadBean/local"); 
                }catch(NamingException (http://docs.oracle.com/javase/7/docs/api/javax/naming/NamingException.html) name){ 
                     throw new ECSystemException(name.getMessage(),BillCreationAction.class.getName(),METHOD_NAME); 
                } 
                ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String (http://www.coderanch.com/t/410859/java/java/String-StringBuffer-StringBuilder-Performance)> arrCheckedItems = new ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String>(); 
                StringTokenizer (http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html) billitemString = new StringTokenizer (http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html)(request.getParameter("dmCheckBoxSelectionList_Hidden"),","); 
                while(billitemString.hasMoreTokens()){ 
                     String billitem_id = billitemString.nextToken(); 
                     arrCheckedItems.add(billitem_id); 
                } 
                ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String> arrUnCheckedItems = new ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String>(); 
                StringTokenizer (http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html) billitemString2 = new StringTokenizer (http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html)(request.getParameter("dmCheckBoxUnSelectionList_Hidden"),","); 
                while(billitemString2.hasMoreTokens()){ 
                     String billitem_id = billitemString2.nextToken(); 
                     arrUnCheckedItems.add(billitem_id); 
                } 
                billItemsListFacadBean.updateDeliveryMemoSelectionList(arrCheckedItems, arrUnCheckedItems); 
 
 After this now when i try to access this variable in BillFacadBean(SLSB)  using the below code the value of the instance variable(arrCummulativeDMSelectionList) of the SFSB is null and hence the method 
 fetchDeliveryMemoSelectionList returns an empty arraylist. 
 
                BillItemsListFacadBeanInterface billItemsListFacadBean = null; 
           try{ 
                billItemsListFacadBean = (BillItemsListFacadBeanInterface) new InitialContext (http://docs.oracle.com/javase/7/docs/api/javax/naming/InitialContext.html)().lookup("inticraftEAR/BillItemsListFacadBean/local"); 
           }catch(NamingException (http://docs.oracle.com/javase/7/docs/api/javax/naming/NamingException.html) name){ 
                throw new ECSystemException(name.getMessage(),BillFacadBean.class.getName(),METHOD_NAME); 
           } 
           if(null != billItemsListFacadBean){ 
                arrSelectedBillItems = billItemsListFacadBean.fetchDeliveryMemoSelectionList(); 
           } 
 
 Code of SFSB BillItemsListFacadBean  is as below: 
 
 package com.inticraft.facad; 
 
 import java.util.ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html); 
 import java.util.Iterator (http://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html); 
 import java.util.List (http://docs.oracle.com/javase/7/docs/api/java/util/List.html); 
 
 import javax.annotation.PostConstruct (http://docs.oracle.com/javase/7/docs/api/javax/annotation/PostConstruct.html); 
 import javax.annotation.PreDestroy (http://docs.oracle.com/javase/7/docs/api/javax/annotation/PreDestroy.html); 
 import javax.ejb.PostActivate (http://docs.oracle.com/javaee/6/api/javax/ejb/PostActivate.html); 
 import javax.ejb.PrePassivate (http://docs.oracle.com/javaee/6/api/javax/ejb/PrePassivate.html); 
 import javax.ejb.Remove (http://docs.oracle.com/javaee/6/api/javax/ejb/Remove.html); 
 import javax.ejb.Stateful (http://docs.oracle.com/javaee/6/api/javax/ejb/Stateful.html); 
 import javax.interceptor.Interceptors (http://docs.oracle.com/javaee/6/api/javax/interceptor/Interceptors.html); 
 
 import com.inticraft.ejbutil.CommitAndCloseInterceptor; 
 import com.inticraft.ejbutil.LoggingInterceptor; 
 import com.inticraft.exceptions.ECException; 
 
 /** 
  * Session Bean implementation class BillItemsListFacadBean 
  */ 
 @Interceptors({LoggingInterceptor.class}) 
 @Stateful 
 public class BillItemsListFacadBean implements BillItemsListFacadBeanInterface { 
      private List <String> arrCummulativeDMSelectionList; 
      private String first_element; 
     /** 
      * Default constructor. 
      */ 
     public BillItemsListFacadBean() { 
         // TODO Auto-generated constructor stub 
     } 
 
     @PostConstruct 
     @PostActivate 
     public void openConnection(){ 
 
     } 
 
     @PrePassivate 
     @PreDestroy 
     public void cleanup() { 
 
 
     } 
 
     @Remove 
     @Interceptors({CommitAndCloseInterceptor.class}) 
     public void closeDM() throws ECException{ 
          arrCummulativeDMSelectionList = null; 
     } 
 
 
 
      @Interceptors({CommitAndCloseInterceptor.class}) 
     public void updateDeliveryMemoSelectionList(ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String> arrSelectedItems , ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String>arrUnSelectedItems) throws ECException { 
           arrCummulativeDMSelectionList = new ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String>(); 
          //Step1 iterate through the unselecteditems and remove from the cummulative list if any entry matches 
          Iterator <String>it1 = arrUnSelectedItems.iterator(); 
          while(it1.hasNext()){ 
               String unSelectedItem = (String)it1.next(); 
               if(arrCummulativeDMSelectionList.contains(unSelectedItem)){ 
                    arrCummulativeDMSelectionList.remove(unSelectedItem); 
               } 
          } 
          Iterator <String>it2 = arrSelectedItems.iterator(); 
          while(it2.hasNext()){ 
               String selectedItem = (String)it2.next(); 
               if(!arrCummulativeDMSelectionList.contains(selectedItem)){ 
                    arrCummulativeDMSelectionList.add(selectedItem); 
                    first_element = selectedItem; 
               } 
          } 
     } 
 
      @Interceptors({CommitAndCloseInterceptor.class}) 
     public ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<String> fetchDeliveryMemoSelectionList() throws ECException { 
           if(null == arrCummulativeDMSelectionList){ 
                return new ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)(); 
           }else{ 
                return new ArrayList (http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)(arrCummulativeDMSelectionList); 
           } 
 
     } 
 
 
 } 
 
 I am not understaning , why is this variable value null always ie the STATE IS NOT BEING MAINTAINED. Also another thing that i observed was in the jobss jmx console , every time this SFSB was accessed the count got incrmented by 1 , which is making me think , every time this bean is called a new instance of the bean is created , instead of returning the already created instance. I am going nuts over this . any help is greatly appreciated. Thanks a ton in advance and also please let me know if you would need any other information.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740619#740619]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120608/61443e58/attachment-0001.html 


More information about the jboss-user mailing list