javax.ejb.RemoveException: Could not remove 18;
lviggiano Nov 1, 2001 3:30 PMHi,
I'm having problem calling this code from a method in a stateless sessionbean:
public Long updateCompanyAndMainAddress(CompanyBean companyBean,
AddressBean mainAddressBean)
throws RemoteException {
mainAddressBean = fixAddress(mainAddressBean);
try {
Company company = companyHome.findByPrimaryKey(companyBean.id);
Address address = company.getMainAddress();
if (null != address) {
if (null != mainAddressBean)
address.replace(mainAddressBean); // update the address
else {
company.setMainAddressId(null); // removes the address
address.remove(); // <-- here comes the error
}
} else {
if (null != mainAddressBean) {
address = addressHome.create(mainAddressBean); // insert the address
company.setMainAddressId(address.getId());
}
}
return company.getId();
} catch (CreateException createEx) {
throw new RemoteException(createEx.getMessage(), createEx);
} catch (FinderException finderEx) {
throw new RemoteException(finderEx.getMessage(), finderEx);
} catch (RemoveException removeEx) {
throw new RemoteException(removeEx.getMessage(), removeEx);
}
}
I get the following error:
[Address] AddressBeanImpl.ejbRemove id = 18
[CompanyHandler] CompanyBeanImpl.ejbStore id = 7
[CompanyHandler] CompanyBeanImpl.ejbStore mainAddress id = null
[CompanyHandler] AddressBeanImpl.ejbStore id = 18
[tapir/DataSource] Pool tapir/DataSource [0/1/10] returned object org.opentools.
minerva.jdbc.xa.wrapper.XAConnectionImpl@3411a to the pool.
[CompanyHandler] TRANSACTION ROLLBACK EXCEPTION:Could not remove 18; nested exce
ption is:
javax.ejb.RemoveException: Could not remove 18; nested exception is:
java.rmi.RemoteException: Could not remove 18; nested exception is:
javax.ejb.RemoveException: Could not remove 18
[CompanyHandler] java.rmi.RemoteException: Could not remove 18; nested exception
is:
[CompanyHandler] javax.ejb.RemoveException: Could not remove 18
[CompanyHandler] javax.ejb.RemoveException: Could not remove 18
[CompanyHandler] at org.jboss.ejb.plugins.jaws.jdbc.JDBCRemoveEntityComma
nd.execute(JDBCRemoveEntityCommand.java:56)
[CompanyHandler] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.rem
oveEntity(JAWSPersistenceManager.java:168)
[CompanyHandler] at org.jboss.ejb.plugins.CMPPersistenceManager.removeEnt
ity(CMPPersistenceManager.java:466)
[CompanyHandler] at org.jboss.ejb.EntityContainer.remove(EntityContainer.
java:331)
[CompanyHandler] at java.lang.reflect.Method.invoke(Native Method)
[CompanyHandler] at org.jboss.ejb.EntityContainer$ContainerInterceptor.in
voke(EntityContainer.java:692)
[CompanyHandler] at org.jboss.ejb.plugins.EntitySynchronizationIntercepto
r.invoke(EntitySynchronizationInterceptor.java:208)
[CompanyHandler] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invok
e(EntityInstanceInterceptor.java:186)
[CompanyHandler] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxI
nterceptorCMT.java:133)
[CompanyHandler] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransac
tions(TxInterceptorCMT.java:263)
[CompanyHandler] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInter
ceptorCMT.java:99)
[CompanyHandler] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(Secu
rityInterceptor.java:190)
[CompanyHandler] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterc
eptor.java:195)
[CompanyHandler] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.
java:323)
[CompanyHandler] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoke
r.invoke(JRMPContainerInvoker.java:482)
[CompanyHandler] at org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.inv
oke(EntityProxy.java:146)
[CompanyHandler] at $Proxy640.remove(Unknown Source)
...
The problem seems that the address.remove() is called prior than the ejbStore of company.setMainAddressId(null), and then the constraint on the oracle db makes the exception to occur.
This can be verified by the top lines included above:
[Address] AddressBeanImpl.ejbRemove id = 18
[CompanyHandler] CompanyBeanImpl.ejbStore id = 7
[CompanyHandler] CompanyBeanImpl.ejbStore mainAddress id = null
[CompanyHandler] AddressBeanImpl.ejbStore id = 18
The 'nice' thing is that if I put the same code in a JSP it works. I moved in a stateless session bean to minimize remote method invokations, and I would like that this code works here.
I'm using JBoss 2.2.2 with (the already integrated) Tomcat 3.2.2, and Oracle 8i as database.
Can anyone explain me why the ejbRemove of Address is called prior than the ejbStore of Company, and why after that is called ejbStore of Address (that should just been removed??)