EJB 2.1 local interface != EJB 3.0 local business interface
By vbkraemer on Mar 28, 2006
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
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"