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...);
}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-StringBui...
arrCheckedItems = new ArrayList
(
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<Str...);
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)(...);
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)<Str...
arrUnCheckedItems = new ArrayList
(
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<Str...);
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)(...);
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...);
}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;
}
(a)Interceptors({CommitAndCloseInterceptor.class})
public void updateDeliveryMemoSelectionList(ArrayList
(
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<Str...
arrSelectedItems , ArrayList
(
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<Str...
throws ECException {
arrCummulativeDMSelectionList = new ArrayList
(
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<Str...);
//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;
}
}
}
(a)Interceptors({CommitAndCloseInterceptor.class})
public ArrayList
(
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html)<Str...
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)(arrCum...);
}
}
}
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&...]