3 Replies Latest reply on Jul 19, 2002 12:38 PM by homerjay

    How to implement "*EJB implements EJBObject"

    jlbakker

      Folks,

      JBOSS 3.0.0

      I am reasonably new to EJB so I may have the wrong approach here. Please bear with me ...

      I have a table with a PK and need to ensure the PK is unique. The table contains users. I think I want to define a method on the home interface that finds a PK (a user ID) that is not in use and claims it:

      public User findByFreeUserID(...) { ... }

      Next, I create a "UserEJB implements EJBObject" that has the body for ejbFindByFreeUserID(...).

      However, now I also need to implement methods such as EJBObject.getEJBHome()! Is this the right approach? If so, is there a canonical implementation for getEJBHome() and the other methods on EJBObject?

      Many thanks,

      John-Luc

        • 1. Re: How to implement "*EJB implements EJBObject"
          homerjay

          Some. You don't have to implement *all* the various methods from the EJBObject, most of these methods are there for you to use within the bean. The method getEJBHome() for example will give you the "Home Object" for this bean, useful if you want to lookup other beans using one of the finder methods. However you do have to implement various ejbLoad(), ejbStore(), ejbCreate() and ejbPostCreate() methods IF you are using Bean Managed Persistance.

          I suggest you find a tutorial, book or on the web (I belive http://java.sun.com has some) and work through a couple of some examples.

          HJ

          • 2. Re: How to implement "*EJB implements EJBObject"
            jlbakker

            All,

            I worked with "http://www.jboss.org/online-manual/HTML/ch04s07.html"

            This one tells me how code a custom finder in my bean. E.g. the example (at the bottom) goes "public class PopulationEJB implements EJBObject {". Unfortunately, EJBObject is an interface and the compiler tell me to provide the body for getEJBHome too. Should I be extending another object? Is the documentation in error?

            Regards,

            John-Luc

            • 3. Re: How to implement "*EJB implements EJBObject"
              homerjay

              Hi J-L

              I think the example is wrong. For a BMP implementation the Entity Bean must implement "EntityBean". Only the remote interface uses "EJBObject". JBoss will dynamically create the implemetation for the remote interface.

              regards,

              HJ