1 Reply Latest reply on Jul 24, 2002 7:13 PM by bsreekanth

    Dynamic finders using ejbSelect

    bsreekanth

      I am trying to create a dynamic finder using ejbSelect
      When I try to access the methods of local object (getting it from collection returned by dynamic finder) it's throwing exception.
      Dynamic finder is returning collection object. The size of collection is correct
      My code is like this.
      Home:
      --------
      public Collection findDynamicQuery() throws FinderException;

      Bean:
      --------
      public abstract Collection ejbSelectGeneric(String jbossQl, Object[] arguments) throws FinderException;
      public Collection ejbFindDynamicQuery() throws FinderException {
      //construct jbossql and object array
      // call ejbSelectGeneric
      }

      ejb-jar
      --------
      <query-method>
      <method-name>findDynamicQuery</method-name>
      <method-params/></query-method>
      <ejb-ql><![CDATA[ SELECT OBJECT(alert) FROM Alert ]]>
      </ejb-ql>

      <query-method>
      <method-name>ejbSelectGeneric</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.Object[]</method-param>
      </method-params>
      </query-method>
      <ejb-ql><![CDATA[ SELECT OBJECT(alert) FROM TdAlert ]]>
      </ejb-ql>

      josscmp-jdbc.xml
      -----------------
      <query-method><method-name>findDynamicQuery</method-name><method-params/></query-method>

      <query-method>
      <method-name>ejbSelectGeneric</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      <method-param>java.lang.Object[]</method-param>
      </method-params>
      </query-method>
      <dynamic-ql />


      client:
      -------
      The call to findDynamicQuery() is returning a collection of local objects.
      But When I try to invoke a getMethod on the object it,s throwing following error.

      java.lang.IllegalArgumentException: object is not an instance of declaring class
      at java.lang.reflect.Field.get(Native Method)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.getPrimaryKeyValue(JDBCAbstractCMPFieldBridge.java:182)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.injectPrimaryKeyIntoInstance(JDBCEntityBridge.java:587)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:70)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:62)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.loadEntity(JDBCStoreManager.java:572)
      at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistenceManager.java:410)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.loadEntity(CachedConnectionInterceptor.java:353)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:262)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:152)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:176)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:183)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:296)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      ......
      .......
      2002-07-24 14:12:07,551 ERROR [STDERR] java.lang.reflect.InvocationTargetException:
      2002-07-24 14:12:07,551 ERROR [STDERR] javax.ejb.TransactionRolledbackLocalException: Internal error getting primary key field member idAlert; CausedByException is:
      object is not an instance of declaring class; nested exception is:
      javax.ejb.EJBException: Internal error getting primary key field member idAlert; CausedByException is:
      object is not an instance of declaring class; CausedByException is:
      Internal error getting primary key field member idAlert; CausedByException is:
      object is not an instance of declaring class; nested exception is:
      javax.ejb.EJBException: Internal error getting primary key field member idAlert; CausedByException is:
      object is not an instance of declaring class
      2002-07-24 14:12:07,551 ERROR [STDERR] at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:313)
      2002-07-24 14:12:07,551 ERROR [STDERR] at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      ....
      ......

      Can any body have any idea.
      thanks,
      sreek


        • 1. Re: Dynamic finders using ejbSelect
          bsreekanth

          Some more info on the Exception.

          When I try to invoke get calls on objects from collection in the ejbFindDynamicQuery() in the entity bean class, it went well.
          Then i checked the classLoaders.
          what I found id the loaders are different in the entity bean and the session bean (my client with Tx required).
          In the session bean the classloader is:
          org.jboss.mx.loading.UnifiedClassLoader@4f1726 { .//path to ear file }
          In entity bean method:
          org.jboss.proxy.compiler.Runtime@343bb6

          How can I avoid using to differnt classloaders.
          Iam using jboss3.0.1 from sourceforge.

          Thanks.