1 Reply Latest reply on Apr 26, 2002 10:23 PM by Alexander

    Weird exceptions in home.create and object.remove

    Alexander Newbie

      Hi guys,

      I've been plaing with simple (more or less standard) j2ee test application last few days, trying to make it work under JBoss-3.0.0RC1_Tomcat-4.0.3. I have not succeeded, but at least I have now simple unit test and build file, so you can try that too :)

        • 1. Re: Weird exceptions in home.create and object.remove
          Alexander Newbie

          For some reason I could not post the whole message in in one page - in this case attachments don't work.

          So, here is the rest :

          There were several post in JBoss forums, where similar problems were described, most of them without any answer, some of them are a few months old, so I just decided to post it with some "almost working" code.

          Please tell me if you know solutions or workarouns, or that this is documented bug, any ideas would be appreciated :)

          Application consists of two EJB modules, one Web module (test) and one (almost) Client (test) module. First EJB module defines one session (Stateless) and one entity (CMP) bean, it also contains some base classes. Second EJB module contains simple entity (CMP) bean, and refers to session bean from the first EJB module. Client and Web modules provide cactus-based unit tests. The main idea of that unit test is to create, modify, find and remove entity defined in second EJB module via local and remote interfaces.

          Here is test code:

          ...
          protected void setUp() throws Exception {
          ctx = new InitialContext();
          ctx = (Context) ctx.lookup("java:comp/env");
          }
          public void testLocal() throws Exception {
          NamedEntityHome home = (NamedEntityHome) EjbUtils.lookupLocalHomeInterface(ctx, "NamedEntity", NamedEntityHome.class);
          for (int i = 0; i < 5; i++) {
          NamedEntity object = home.create();
          Integer pk = (Integer) object.getPrimaryKey();
          object.setName("test - " + pk);
          assertEquals("test - " + pk, object.getName());
          NamedEntity objectByName = home.findByName("test - " + pk);
          NamedEntity objectByPK = home.findByPrimaryKey(pk);
          assertTrue(objectByName.isIdentical(objectByPK));
          }
          Iterator i = home.findAll().iterator();
          while (i.hasNext()) {
          ((NamedEntity) i.next()).remove();
          }
          }
          public void testRemote() throws Exception {
          NamedEntityRemoteHome home = (NamedEntityRemoteHome) EjbUtils.lookupHomeInterface(ctx, "NamedEntity", NamedEntityRemoteHome.class);
          for (int i = 0; i < 5; i++) {
          NamedEntityRemote object = home.create();
          Integer pk = (Integer) object.getPrimaryKey();
          object.setNameRemote("test - " + pk);
          assertEquals("test - " + pk, object.getNameRemote());
          NamedEntityRemote objectByName = home.findByNameRemote("test - " + pk);
          NamedEntityRemote objectByPK = home.findByPrimaryKey(pk);
          assertTrue(objectByName.isIdentical(objectByPK));
          }
          Iterator i = home.findAllRemote().iterator();
          while (i.hasNext()) {
          ((NamedEntityRemote) i.next()).remove();
          }
          }

          ...

          Errors reported from this code depends on packaging of the application.

          If I include ejb-client (doesn't matter if I include ejb-provider code or not) jars in the web archive, then lookup of local home interface returns Proxy<some number> which can't be class-custed to local home interface loaded by web module class loader; remote home interface is successfully narrowed, but throws NullPointerException somewhere in container implementation of home.create method.

          If I don't include ejb-client jars in web archive, then all lookups, create, and even find methods works, but remove throws strange exceptions in container implementation.


          Most ejb are deployed with "Requied" transaction attribute and unchecked security, the only exception is entiy bean from the first module - it uses "RequiresNew". All entity beans are CMP beans and are mapped by default to Hypersonic SQL (DefaultDS).

          If you want to build and test it on your installation, please correct "local.properties" and "etc/cactus.properties" and execute Ant's build file with "server.deploy" (or just "build") and "test" targets.

          I've included corresponding logs in attached (if it works) jboss-test-cmp.zip


          Here are cuts from test logs (I've included full version in attached jboss-test-cmp.zip)

          1) EJB code isn't included in Web module

          ...
          [java] 1) testLocal(com.alazarllc.test.jboss.ejb.EntityBeanTester)
          [java] java.lang.reflect.UndeclaredThrowableException: java.rmi.ServerException: null; nested exception is:
          [java] java.lang.NullPointerException
          [java] java.lang.NullPointerException
          [java] at org.jboss.util.LRUCachePolicy$LRUCacheEntry.toString(LRUCachePolicy.java:453)
          [java] at java.lang.String.valueOf(String.java:1947)
          [java] at java.lang.StringBuffer.append(StringBuffer.java:370)
          [java] at org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy$ContextLRUList.entryRemoved(LRUEnterpriseContextCachePolicy.java:457)
          [java] at org.jboss.util.LRUCachePolicy$LRUList.remove(LRUCachePolicy.java:389)
          [java] at org.jboss.util.LRUCachePolicy.remove(LRUCachePolicy.java:178)
          [java] at org.jboss.ejb.plugins.AbstractInstanceCache.remove(AbstractInstanceCache.java:256)
          [java] at org.jboss.ejb.plugins.EntityInstanceCache.remove(EntityInstanceCache.java:79)
          [java] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:231)
          [java] at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
          [java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
          [java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
          [java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
          [java] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
          [java] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
          [java] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
          [java] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
          [java] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:315)
          [java] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$EntityProxy.invoke(BaseLocalContainerInvoker.java:415)
          [java] at $Proxy172.remove(Unknown Source)
          [java] at com.alazarllc.test.jboss.ejb.EntityBeanTester.testLocal(EntityBeanTester.java:41)
          ...

          ...
          [java] 2) testRemote(com.alazarllc.test.jboss.ejb.EntityBeanTester)
          [java] java.rmi.ServerException: removing bean lock and it has tx set!; nested exception is:
          [java] java.lang.IllegalStateException: removing bean lock and it has tx set!
          [java] java.lang.IllegalStateException: removing bean lock and it has tx set!
          [java] at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedPessimisticEJBLock.java:469)
          [java] at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:78)
          [java] at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:124)
          [java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
          [java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
          [java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
          [java] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
          [java] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
          [java] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
          [java] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
          [java] at org.jboss.ejb.Container.invoke(Container.java:706)
          [java] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
          [java] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:492)
          [java] at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
          [java] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
          [java] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
          [java] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
          [java] at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:116)
          [java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:96)
          [java] at $Proxy171.remove(Unknown Source)
          [java] at com.alazarllc.test.jboss.ejb.EntityBeanTester.testRemote(EntityBeanTester.java:57)
          ...


          2) EJB code is included in Web module

          ...
          [java] 1) testLocal(com.alazarllc.test.jboss.ejb.EntityBeanTester)
          [java] java.lang.IllegalArgumentException: EJBLocalHome with jndi name 'ejb/local/NamedEntity' and type '$Proxy137' is not instance of 'com.alazarllc.test.jboss.ejb.client.local.NamedEntityHome'
          [java] at com.alazarllc.framework.ejb.EjbUtils.lookupLocalHomeInterface(EjbUtils.java:42)
          [java] at com.alazarllc.test.jboss.ejb.EntityBeanTester.testLocal(EntityBeanTester.java:29)
          ...

          ...
          [java] 2) testRemote(com.alazarllc.test.jboss.ejb.EntityBeanTester)
          [java] java.rmi.ServerException: null; nested exception is:
          [java] java.lang.NullPointerException
          [java] java.lang.NullPointerException
          [java] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1107)
          [java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
          [java] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:230)
          [java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:176)
          [java] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:134)
          [java] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
          [java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
          [java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
          [java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
          [java] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
          [java] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:104)
          [java] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
          [java] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
          [java] at org.jboss.ejb.Container.invoke(Container.java:727)
          [java] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
          [java] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:492)
          [java] at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
          [java] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
          [java] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
          [java] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
          [java] at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:185)
          [java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:96)
          [java] at $Proxy141.create(Unknown Source)
          [java] at com.alazarllc.test.jboss.ejb.EntityBeanTester.testRemote(EntityBeanTester.java:47)
          ...