Saturday, January 28, 2006

EJB3 session visibility

EJB3 started with the claim to reduce the artefacts needed to program with EJBs. Unfortunately if you want to expose a SessionBean locally *and* remotely, you start to either list all business methods in a POJI for the local interface and the same again in an interface for the remote view. If you update the session bean class by a new method, you need to remember to update both interface files (this calls again for generators like Xdoclet ...)

Another variant to acheive the same result is by using the following view pattern:

In this case you only list the business methods in the "Business" interface. IRemote and ILocal are only marker interfaces that just extend the "Business" interface and which carry the respective annotation:

package foo;

import javax.ejb.Local;

public interface ILocal extends Business {
// empty

This way extending the session bean by new methods just means to update one additional file. Unfortunately this yields again four artefacts for this task, which is far from simple.

Are there better ways to do this?

No comments: