PDA

View Full Version : Passivate throws exception



wengatz_n
Nov 16th, 2004, 02:27 AM
Hi,

I implemented a stateful session bean with Springs AbstractStatefulSessionBean.
My session bean is a facade for my business logic implemented as POJO and
managed by Spring.

In method ejbCreate a get my POJO from Spring.In the activate and passivate methods
a load/unload the bean factory.

My problem is that I get an exception when the bean will be passivated.


Following my source code:
========================
public class HelloSFSBBean extends AbstractStatefulSessionBean implements Hello {

// my POJO
Hello hello=null;

public java.lang.String sayHello(String name ){
String result;
try {
result=hello.sayHello(name);
} catch (Exception e){
return "Exception "+e;
}
return result;
}



public void ejbActivate() throws EJBException, RemoteException {
loadBeanFactory();
hello = (Hello)getBeanFactory().getBean("baer");

}


public void ejbCreate() throws EJBException, RemoteException {
loadBeanFactory();
hello = (Hello)getBeanFactory().getBean("baer");
}



public void ejbPassivate() throws EJBException, RemoteException {
unloadBeanFactory();

}

}

the exception trace:
====================
09:20:49,074 WARN [AbstractInstanceCache] failed to passivate, id=e1lseige-6
javax.ejb.EJBException: Could not passivate; failed to save state; CausedByException is:
org.springframework.context.access.ContextJndiBean FactoryLocator
at org.jboss.ejb.plugins.StatefulSessionFilePersisten ceManager.passivateSession(StatefulSessionFilePers istenceManager.java:378)
at org.jboss.ejb.plugins.StatefulSessionInstanceCache .passivate(StatefulSessionInstanceCache.java:85)
at org.jboss.ejb.plugins.AbstractInstanceCache.tryToP assivate(AbstractInstanceCache.java:151)
at org.jboss.ejb.plugins.LRUEnterpriseContextCachePol icy$OveragerTask.run(LRUEnterpriseContextCachePoli cy.java:419)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)java.io.N otSerializableException: org.springframework.context.access.ContextJndiBean FactoryLocator
at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1054)

at java.io.ObjectOutputStream.defaultWriteFields(Obje ctOutputStream.java:1332)
at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1304)
at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1247)
at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1052)

at java.io.ObjectOutputStream.writeObject(ObjectOutpu tStream.java:278)
at org.jboss.ejb.plugins.StatefulSessionFilePersisten ceManager.passivateSession(StatefulSessionFilePers istenceManager.java:370)
at org.jboss.ejb.plugins.StatefulSessionInstanceCache .passivate(StatefulSessionInstanceCache.java:85)
at org.jboss.ejb.plugins.AbstractInstanceCache.tryToP assivate(AbstractInstanceCache.java:151)
at org.jboss.ejb.plugins.LRUEnterpriseContextCachePol icy$OveragerTask.run(LRUEnterpriseContextCachePoli cy.java:419)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)



my spring config
================
<beans>

<bean id="myBaer" class="test.Baer">
<property name="sender"><ref local="jmssender"/></property>
</bean>


<bean id="loadInterceptor" class="test.LoadInterceptor" init-method="init">
<property name="max"><value>15</value></property>
</bean>


<bean id="jmssender" class="test.JMSSender">
<property name="destination"><ref local="destination1"/></property>
<property name="conFac"><ref local="confac1"/></property>
</bean>

<bean id="destination1" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>queue/exercise2</value></property>
</bean>

<bean id="confac1" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>ConnectionFactory</value></property>
</bean>


<bean id="baer" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>test.Hello</value></property>
<property name="target"><ref local="myBaer"/></property>
<property name="interceptorNames">
<list>
<value>loadInterceptor</value>
</list>
</property>
</bean>

</beans>

Could you please help me to find out what's going wrong here?

Thank you very much and best regards
Nicole

Andreas Senft
Nov 16th, 2004, 02:38 AM
I would guess that you need to null out your Hello instance in the passivate method. Otherwise the container will try to serialize it, which it cannot.

Regards,
Andreas

wengatz_n
Nov 16th, 2004, 02:50 PM
Hi Andreas,

thanks for your help, BUT unfortunately it does not help. I still get the same exception:

java.io.NotSerializableException: org.springframework.context.access.ContextJndiBean FactoryLocator

Any futher ideas?

Best regards
Nicole

Andreas Senft
Nov 17th, 2004, 12:42 AM
Just found this in the API documentation of AbstractStatefulSessionBean:

Note: The default BeanFactoryLocator used by this class's superclass (ContextJndiBeanFactoryLocator) is not serializable. Therefore, when using the default BeanFactoryLocator, or another variant which is not serializable, subclasses must call setBeanFactoryLocator(null) in ejbPassivate, with a corresponding call to setBeanFactoryLocator(xxx) in ejbActivate unless relying on the default locator.


Indeed it looks like the locator causes your problem. So hopefully this will help.

Regards,
Andreas

wengatz_n
Nov 18th, 2004, 02:34 PM
Hi Andreas,

your solution helps, now it works fine!

Thanks a lot.
Nicole