1 Reply Latest reply on Sep 25, 2002 10:51 AM by sseaman

    Getting reference to Local Interface

      I've got a few ejb bean relationships going and since I cannot use these relationships from remote interfaces I have tried to make a few session beans that can access the information and their relationships.

      The issue I have hit is that I cannot figure out how to get references to the LOCAL interfaces.

      The article:
      http://www.tiburon-e-systems.com/nl20020901/article.html
      that gets pointed to a good bit actually deals with remotes and not locals so I still would not be able to get to the relationships.

      It there any way to either:
      a) get to the relationship remotely (the specs say no) or
      b) get to the local interfaces via a session bean or
      c) modify the entity bean to allows access to the relationship.

      I've been fighting this for over a day and can't figure it out.

      Thanks!

        • 1. Re: Getting reference to Local Interface

          Figured it out on my own.

          For those who might want the answer:

          You need to define an <ejb-local-ref> tag set within your ejb-jar.xml

          Say you have an entity bean named User and you want to be able to get to it locally. In the tags for the User bean you need to have the following:
          <ejb-local-ref>

          <!-- this is what to use in the lookup -->
          <ejb-ref-name>local/User</ejb-ref-name>
          <ejb-ref-type>Entity</ejb-ref-type>
          <local-home>com.blah.entity.UserHome</local-home>
          com.blah.entity.User
          <!-- this is the entity bean -->
          <ejb-link>User</ejb-link>
          </ejb-local-ref>

          Please note that com.blah.entity.UserHome and com.blah.entity.User implement the Local interfaces. Most people would have them named UserLocalHome and UserLocal, but I used JBuilder to make the beans (took too long in JEdit) and JBuilder names them differently.

          Anyway, in your code, to reference the local interfaces you would do the following:
          // Get the reference to the LOCAL Home
          UserHome home = (UserHome)ctx.lookup("local/User");
          // Get the reference to the LOCAL User object
          User user = (User)home.findByEmailAddress("sloan@sgi.net");
          // Print some stuff
          System.out.println(user.getEmailAddress()+
          " "+user.getPassword());
          // This actually returns another LOCAL object
          // that is created by an ejb-relationship.
          System.out.println(user.getLeagueContact().
          getFirstName());

          And that is really all that there is to it.

          Remember that when dealing with ejb-relationships, they only work locally. So the code above would have to be in a bean within the same JVM as the User objects.