EJB programming & troubleshooting: ejb reference

  1. ejb reference (3 messages)

    In my session bean A, I call a helper class instance, which will lookup local interface of another bean B. Now question is the helper class can't find B, if I add ejb-ref of B to A in ejb-jar.xml, then server works well.

    Can't I lookup local interface of bean in a non-ejb object?

    Threaded Messages (3)

  2. ejb reference[ Go to top ]


    Your helper class will work exactly as the code in the EJB, It's not the class the code is writtenin that is important, it is the context the code is executed in. If you have a bean A, code in a helper class used by A will work in exactly the same way a code written in the ABean class implementing the bean code.

    Normally, when I write helper classes (like data access objects), I try to make the "context independent". This means I give external references (like another EJB or a DataSource) in the contructor or in the method call. With this design, I don't get hidden references between components.

    Example: If I have a nice little class looking like a simple value object, but that class references an EJB, I must execute this class in a context (=a J2EE container) where the referenced EJB is accessable. The reference is "hidden" within the value object, the value object will fail if I use it in a stand-slone JVM. If a pass the EJB reference in the cunstructor, the reference will be more explicit to programmers using my object.

    However, this is my personal recommendation. I know (as an example) that the data access object pattern often recommends encapsulation of the JDBC connection management within the data access objects.

  3. ejb reference[ Go to top ]

    thanks for ur reply. What confuses me most is I don't know what kind of codes should be put in helper class. For example, some objects should be kept in memory for a long time, but I can't use session bean for it will timeout, so I use a helper class to store these objects. Is there any method better?
  4. another question[ Go to top ]

    as ur written, if ejb call another object, that object is executed in the container. while if that object start a new thread, does this thread run in the container too? if so, then will management of user-defined thread myself affect the container?