0 Replies Latest reply on Feb 15, 2003 8:47 PM by Kyle VanderBeek

    Is getEJBObject useless from an <ejb-local-ref>?

    Kyle VanderBeek Newbie

      I have a stateless Session bean named "Authenticator" which performs essential login and password change actions on a CMP bean named "User". For somewhat obvious reasons, my UserRemote and UserLocal interfaces are different: UserLocal has getPassword() and setPassword, while UserRemote lacks them. I don't want front-end programmers even thinking they have access to these fields. They need to go through Authenticator.

      Authenticator.login() returns a UserRemote reference on successful login. The front end can then manipulate this reference normally.

      In login(), I find the user in question via their username and an <ejb-local-ref> at java:comp/env/ejb/User . Right now, if everything goes right, I have to do a gross little hack involving a full new lookup of the UserHomeRemote in the greater context, narrow()'ing it, and calling findByPrimaryKey(user.getId()).

      It seems to me that this is exactly what getEJBObject() is for. I have defined in UserBean.java a method called getUserRemote() which simply does:

      return (UserRemote)ctx.getEJBObject();

      this method is exposed in the UserLocal implementation
      (ctx being the EntityContext I store in a member variable from the setEntityContext() call).

      However, it doesn't work. I always get an IllegalStateException that "No remote interface defined." In fact, there is a remote interface defined in ejb-jar.xml .

      Am I missing something? Is there something of a difference in the way a CMP Entity Bean comes into the container via a local ref? This seems to be a useful sort of functionality.