Hi
An entity bean holds a refrence to another entity bean (due to speed up access to the parent bean).
This works well as long as the bean is not passivated . After activating the bean,
the reference points to a wrong parent bean. What's wrong or is this not allowed?
Following a short code extraction:
==================================
First version, which doesn't work:
public class TaskStepBean extends ......AbstractEntityBean{
private long jParentId;
private ParentBeanLocal jParentBeanLocal;
/**
* @ejb.interface-method
* In local interface only!
*
* @return
*/
public ParentBeanLocal getParent() throws FinderException {
if( this.jParentBeanLocal == null){
final ParentBeanLocalHome home;
home = (ParentBeanLocalHome)this.getServiceLocator().getLocalHome(ParentBeanLocalHome.class);
this.jParentBeanLocal = home.findById( this.jParentId);
}
return this.jParentBeanLocal;
}
}
==================================
Second version adds the ejbPassivate and ejbActivate methods(doesn't work). Even if ejbActivate() was called, the reference is not null ?!
/**
*
*/
public void ejbPassivate(){
this.jParentBeanLocal = null;
super.ejbPassivate();
}
/**
*
*/
public void ejbActivate(){
super.ejbActivate();
this.jParentBeanLocal = null;
}
==================================
Third version with a modified getParent() method (works):
/**
* @ejb.interface-method
* In local interface only!
*
* @return
*/
public ParentBeanLocal getParent() throws FinderException {
if( this.jParentBeanLocal != null && this.jParentBeanLocal.getId() != this.jParentId){
this.jParentBeanLocal = null;
}
if( this.jParentBeanLocal == null){
final ParentBeanLocalHome home;
home = (ParentBeanLocalHome)this.getServiceLocator().getLocalHome(ParentBeanLocalHome.class);
this.jParentBeanLocal = home.findById( this.jParentId);
}
return this.jParentBeanLocal;
}