LocalHome object is null and causes IllegalArgumentException
mart Apr 2, 2003 3:50 PMDear reader,
I have encountered the following problem in JBoss 3.0.4.
I have 2 tables (database), Address and PostalAddress. An Address can have a PostalAddress (or none). Thus 0..1 relation. Address therefore contains a foreign key that links to PostalAddress.
Both are implemented using an entity bean (bean-managed persistance). In Address I have a method to set/get the stub of PostalAddress.
public PostalAddressLocal getPostalAddressLocal() {
return localPostalAddressFK;
}
public void setPostalAddressLocal(PostalAddressLocal localAddress) {
this.localPostalAddressFK = localAddress;
}
Both methods are at the local interface of AddressBean.
The error occurs as soon as ejbStore() is called. In ejbStore() the method getPostalAddressLocal() is called to get the postal address stub (and from that the primary key, which will be the foreign key). But the method returns null (as the stub is null, this address does not have a postal address). getPostalAddressLocal() is called on a local interface in ejbStore (the way it should be done normally) and not called directly. A final note: ejbStore() actually uses a different class to store itself, but nevertheless the problem is the same.
The exact error thrown:
ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException, causedBy:
java.lang.IllegalArgumentException: Attempt to remove a lock for a null object
at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:103)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:124)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:301)
at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
It seems it tries to unlock the stub when the method is called, but as it is null something goes wrong. Can anyone shed any light on this? Maybe I just can't use 'null' stubs and they always must be set. But then I would not know how to implement the relation sketched above.
Thank you very much for your time!