2 Replies Latest reply on Nov 17, 2003 7:38 AM by darranl

    Lookup of Local interface from POJO...

    wesleyhall

      Hi,
      Would anyone be able to tell me if it is possible to do a lookup of a entity bean local interface from a plain java object?

      We are using an interface to decouple our persistence layer (for a potential future move to hibernate or JDO) the entity bean implementation of this interface need to lookup the CMP entity beans and call the appropriate methods.

      Im not sure there is a way to set up java:comp/env/... from a POJO so is there another solution?

      Thank you for your time

      Regards

      Wesley Hall

        • 1. Re: Lookup of Local interface from POJO...
          jcordes

          Yes, it is possible when both the POJO and your EJB's reside in the same vm. What you're trying to do, is to use the Business Delegate Pattern to decouple business logic and underlying persistence from the front-end (i.e. web). I'm making heavy use of it so it for sure works ;-), although I still prefer to use a session bean as a facade. Nevertheless it should work with entity beans like this:

          Properties p = new Properties();
          // init properties here ...
          InitialContext ctx = new InitialContext(p);
          MyEntityLocalHome myEntityHome = (MyEntityLocalHome)ctx.lookup("java:comp/env/ejb/MyEntityLocalHome");

          I've realized an alternative implementation in Hibernate for my project (currently for reading only) and plugged it in seamlessly by using Business Delegates and configuration files, cool ...

          HTH,

          Jochen.

          • 2. Re: Lookup of Local interface from POJO...
            darranl

            If you are running inside the JBoss JVM replace

            Properties p = new Properties();
            // init properties here ...
            InitialContext ctx = new InitialContext(p);

            with

            InitialContext ctx = new InitialContext();

            The internal JNDI configuration will be used to ensure that your calls don't go over RMI.