Insert Witty Irony Here

vince kraemer's Weblog


20060328 Tuesday March 28, 2006

EJB 2.1 local interface != EJB 3.0 local business interface The LocalHome is the business interface?

No, but kind of....

My brother was working on writing a Java EE 5 client of a J2EE 1.4 stateless session bean to test this basic evolution use-case when he discovered this the hard way. The first test that he did was to use the @EJB annotation in a servlet to access a J2EE 1.4 bean [an EJB 2.1 bean].

I have to admit that he did not read the EJB 3.0 spec regarding "how" to do this... Since Java EE 5 is about 'ease of development', he figured, "How hard could it be. I define the business methods of an EJB on its local (or remote) interface, so I would write something like

    @EJB com.sun.brotherofvbk.eoetest.SessionBeanLocalInterface bean
    
to call business methods of my J2EE 1.4 EJB inside my Java EE 5 servlet"

BZZT! Wrong. Thanks for playing.

Despite the fact that a number of folks consider the Local or Remote interface of a J2EE 1.4 EJB to be the correct place to define business methods (or interface) of an EJB, IT IS NOT A BUSINESS INTERFACE. [See "JSR 220: Enterprise JavaBeans™,Version 3.0 EJB Core Contracts and Requirements", Proposed Final Draft, section 3.4]

When you use injection for existing EJBs that are implemented against the 2.1 (or earlier) specifications, you must inject the appropriate Home interface. You can then call methods on that interface. My brother would recommend that you call create() and then call the business method that you wanted to actually execute...

All of this is spelled out in the EJB 3.0 "core" specification in section 3.6.1.

So, as the Type-it brothers would say, "Don't code like my brother" (2006-03-28 13:17:20.0) Permalink

Comments:

Post a Comment:

Comments are closed for this entry.

Calendar

« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

RSS Feeds

XML
All
/5 in 5
/Compile Time
/Ease of Evolution
/General
/GlassFish
/Gotchas
/Java
/Music
/NetBeans
/Sailfin

About Me

Photo of Vince Kraemer
Short Bio

Search

Links


Navigation



Subscribe with Bloglines Add to Technorati Favorites

Referers

Today's Page Hits: 338