1 Reply Latest reply on Aug 19, 2002 5:02 AM by Hezekiel

    feature/bug in EntityContainer.findLocal

    Hezekiel Newbie

      I try to be as brief as possible.

      The EJBLocalHome defines only remove method (probably so that the user can specify different ways to find/create her beans). I try to fit most of my beans into the same mould, e.g. most of them have the same finder and create methods. Here's an example, the basic entitybeans in the application extend this interface.

      public interface MyLocalHome extends EJBLocalHome
      public MyLocalObject create(DataObject data) throws CreateException;
      public MyLocalObject findByPrimaryKey(int pk) throws FinderException;
      This is very convenient since it allows me to use same exception handling (and other) logic in the session facade.
      However the code in EntityContainer.findLocal checks for Multifinder operations by determining if the invocation methods return type is the same than the local class. If you are using methods from the base interface this is not the case and operation is found to be multifinder.

      I checked out the 3_0_1 from the cvs and did the following modification (quick hack) which solved the problem for me.

      // Multi-finder?
      // (Original)
      // if (!mi.getMethod().getReturnType().equals(getLocalClass()))
      if (!mi.getMethod().getReturnType().getPackage().equals(getLocalClass().getPackage()))

      I assume that the collections that are to be returned from the findBySomeCriteria are not part of the same package that the bean with it's interfaces are. Obviously this is not the "final" solution but it lets me implement entity beans with common home and local interfaces. I'll try to look from the EJB specs tomorrow whether this kind of behaviour is allowed or not. I think that the no inheritance rule concerns only the inheritance between entity beans and does not restrict you from inheriting your bean implementation from some vanilla java base class.

      Please respond quickly since this kind of functionality saves me from s**tloads of copy pasting.

      I have bought the "expensive" documentation bundle ;-)

        • 1. Re: feature/bug in EntityContainer.findLocal
          Hezekiel Newbie

          Something from the specs (EJB 2.1 final draft):

          //This clause allows inheritance for interfaces:
          The remote home interface is allowed to have superinterfaces. Use of interface inheritance is subject to the RMI-IIOP rules for the definition of remote interfaces.
          //And this practically takes it away :
          The return type for a find method must be the entity bean's remote interface type (for a single-object finder), or a collection thereof (for a multi-object finder).
          Or how should one interpret this? Is the return type from a finder method the entity bean's remote interface type if it is it's supertype? Is the example from the previous post against the spec? If so, the specification sucks... Please help me out here... if I can't use interface inheritance with the entity beans I'm forced to write (number of different beans * handling logic) more code that with the current solution.