users@glassfish.java.net

Re: Using EJB 3.0 session bean from J2EE 1.4 web project

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Tue, 02 Sep 2008 15:51:35 -0400

Thank you! I have a couple of questions:

1) Please confirm I understand correctly: The LocalHome interface I
create must extend EJBHome. It needs only a create method and I am
free to make up the method parameters as long as the EJB implements
it. It must return the Local interface, and throw CreateException.

public interface TransHistoryLocalHome extends EJBHome {
    public TransHistoryLocal create() throws CreateException;
}


2) Do I need to create a different Local interface for use by EJB 2.x
clients than my existing Local interface? They would be identical.

I'll give this a try tonight.


Thanks,
Ryan

glassfish_at_javadesktop.org wrote:
> Hi Ryan,
>
> The reason you haven't seen it anywhere is that the spec doesn't require that EJB 3.0 business interfaces be directly available to pre-Java EE 5 components. If the web application must be J2EE 1.4 style your only portable option is to expose an EJB 2.x "adapted" LocalHome view from your EJB 3.0 bean. A bean can expose multiple views so you don't have to remove whatever other business interface(s) the bean already implements. Since the web app is in the same .ear you will then have access to the 2.x LocalHome view of the target bean.
>
> Do the following :
>
> 1) implement the LocalHome and Local interfaces according to the old EJB 2.x rules
>
> 2) Add a @LocalHome(My2xLocalHome.class) annotation on the stateless session bean class.
> Note that you use the 2.x LocalHome interface, not the 2.x Local interface, in the annotation. The Local interface is derived from the create method on the LocalHome so it doesn't need to appear anywhere on the bean class itself.
>
> 3) Add an ejb-local-ref in the web application's web.xml to create an local ejb dependency on the target 2.x LocalHome/Local view of the stateless session bean. Put the beanName of the target stateless session bean in the ejb-link element. The beanName is either the value of the @Stateless name() attribute or if that's not set the *un*qualified name of the bean class.
>
> <ejb-local-ref>
> <ejb-ref-name>my_slsb</ejb-ref-name>
> <ejb-ref-type>Session</ejb-ref-type>
> <local-home>com.acme.My2xLocalHome</local-home>
> <local>com.acme.My2xLocal<local>
> <ejb-link>MySlsb</ejb-link>
> </ejb-local-ref>
>
> 4) Look up the reference in the web component's environment naming context. E.g. if the ejb-ref-name of the ejb-local-ref is my_slsb the lookup would be
>
> My2xLocalHome mlh = (My2xLocalHome) new InitialContext().lookup("java:comp/env/my_slsb");
>
> The client has no idea the bean is implemented using the 3.0 API so it completely follows the 2.x client programming model :
>
> My2xLocal my2xLocal = mlh.create();
>
> ...
>
>
> Here are some other resources to look at on these topics :
>
> http://blogs.sun.com/enterprisetechtips/entry/ejb_3_0_compatibility_and
>
> https://glassfish.dev.java.net/javaee5/ejb/examples/Adapted.html
>
> https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#EJB_ejb-ref_ejb_local_ref
>
> --ken
> [Message sent by forum member 'ksak' (ksak)]
>
> http://forums.java.net/jive/thread.jspa?messageID=296762
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>