users@glassfish.java.net

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

From: <glassfish_at_javadesktop.org>
Date: Tue, 02 Sep 2008 13:27:07 PDT

>
> public interface TransHistoryLocalHome extends
> EJBHome {

EJBLocalHome instead

> public TransHistoryLocal create() throws
> CreateException;

Right, must have 0 params since it's for a stateless session bean.
You don't have to implement a corresponding "ejbCreate" method
on the bean class.

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

Yes, the 2.x Local interface is distinct from the 3.0 Local business interface.
They can define the same methods.

One thing to note is if you previously defined the local business interface
by putting it in the bean class implements clause without annotating it with
@Local, you'll need to explicitly add the @Local annotation. That default
only applies when the bean doesn't expose any other view. Once @LocalHome
is there, you'll need to specifically state that the Local business interface is
indeed a local business 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/Ad
> apted.html
> >
> >
> https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.htm
> l#EJB_ejb-ref_ejb_local_ref
> >
> > --ken
> > [Message sent by forum member 'ksak' (ksak)]
> >
> >
> http://forums.java.net/jive/thread.jspa?messageID=2967
> 62
> >
> >
> ------------------------------------------------------
> ---------------
> > To unsubscribe, e-mail:
> users-unsubscribe_at_glassfish.dev.java.net
> > For additional commands, e-mail:
> users-help_at_glassfish.dev.java.net
> >
> >
> >
>
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail:
> users-help_at_glassfish.dev.java.net
[Message sent by forum member 'ksak' (ksak)]

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