users@glassfish.java.net

No local JNDI environment for Timer Beans?

From: <glassfish_at_javadesktop.org>
Date: Tue, 29 Apr 2008 14:23:55 PDT

GF info:
Starting Sun Java System Application Server 9.1_02 (build b04-fcs) ...

I have in my session bean:

[code]
@Stateless
public class MySessionBean implements MySessionLocal {

    @Resource
    TimerService timerService;
    @EJB(name = "ejb/OtherSessionBeanEJB", beanName = "OtherSessionBean")
    OtherSessionLocal sb;

    public MySessionBean() {
    }

    @Timeout
    public void timerRun(Timer timer) {
        WorkClass w = new WorkClass();
        w.doSomething();
    }

    public void setupTimer() {
        WorkClass w = new WorkClass();
        w.doSomethingElse();
    }
}
[/code]

I also have:

[code]
public class MyLookup {
    public static OtherSessionLocal lookupOtherSessionBean() {
        try {
            Context c = new InitialContext();
            return (OtherSessionLocal) c.lookup("java:comp/env/ejb/OtherSessionBean");
        } catch(NamingException ne) {
            ne.printStackTrace();
        }
    }
}
[/code]

The problem is my WorkClass calls MyLookup to look up the session bean reference. This works fine for the setupTimer method, but when the timer fires and calls timerRun(...), MyLookup can NOT see OtherSessionBean.

The JNDI does not seem to be properly initialized.

The only way around this seems to be is call OtherSessionBean via a Remote interface, which I'd rather not do. Seems to be that the timerRun should have the same JNDI environment that the normal session bean has.

Am I mistaken? Am I missing something here?
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=272117