2 Replies Latest reply on Jan 29, 2002 1:39 PM by dsundstrom

    Generic findByPrimaryKey method

    abrasax

      Hi all,

      I'd like to call some methods of my entity beans without explicitly knowing their specific home/remote interface (only by knowing their JNDI).

      So, I've written 2 generic interfaces -- the 1st one is extended by all the home interfaces of my entity beans, the 2nd one by their remote interfaces. The generic home interface looks like that:

      public interface GenHome extends EJBHome {
      public GenRemote findByPrimaryKey(Integer pk);
      [other generic home methods]
      }

      where the GenRemote is the generic remote interface.

      I then expected, it would be possible to call the entity beans finders in th following fashion:

      GenHome some_home;
      GenRemote some_entity;
      ... //here getting the some_home and the some_key somehow
      some_entity = some_home.findByPrimaryKey(some_key);
      ... //here doing with the some_entity something

      But I always get exception like:
      Unknown finder: public abstract cz.transoft.generic.ejb.TOMERemote cz.transoft.gis.ejbEBHypertext.EBHypertextHome.findByPrimaryKey(java.lang.Integer) throws java.rmi.RemoteException,javax.ejb.FinderException java.lang.reflect.UndeclaredThrowableException

      When I write EJB-QL for the findByPrimaryKey (but this is not correct, is it?), I get collection, but I want, of course simple remote interface instead.

      Can someone suggest solution to this, please?

      Regards
      Martin

        • 1. Re: Generic findByPrimaryKey method
          abrasax

          Oh, sorry, the TOMERemote interface is of course the GenRemote interface (I only renamed it for purposes of the post)...

          Please, can someone give me advice?

          Martin

          • 2. Re: Generic findByPrimaryKey method
            dsundstrom

            A finder must return a collection or the exact interface of the entity, so you specifically can't have it return GenRemote. You can use reflection to do this.

            Remeber that the EJB spec requires you to PortableRemoteObject.narrow the object returned from the jndi lookup.