[
http://jira.jboss.com/jira/browse/JBAS-5036?page=comments#action_12390401 ]
Arto Huusko commented on JBAS-5036:
-----------------------------------
The type of the local interface is apparently deduced from the return
type of the
create method
Just to be clear about this, I didn't meant that this is what JBoss is doing now (it
isn't), but I meant to say what you should do, as in:
You should apparently deduce the type of the local interface from the return type of the
create method in the home interface, since there are no annotations for it.
Local home create() implementation returns wrong type
-----------------------------------------------------
Key: JBAS-5036
URL:
http://jira.jboss.com/jira/browse/JBAS-5036
Project: JBoss Application Server
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: EJB3
Affects Versions: JBossAS-4.2.1.GA
Reporter: Arto Huusko
Assigned To: Carlo de Wolf
Local home (and presumably remote, too) implementation for EJB 3 sessions creates an
object that is an instance of the local *business* interface of the EJB 3 session, and
returns that. This is contrary to EJB 3 specification, which says that local home create
methods must return an instance of the local interface of the EJB 3 session (as in: not
local business interface).
The type of the local interface is apparently deduced from the return type of the create
method in the local home interface (there is no annotation for it).
For beans that follow the specification, this causes a class cast exception when create()
is called: the local home interface is specified to return an instance of local interface,
but the implementation JBoss supplies creates a instance of local business interface (I
presume so, because changing local home to return that works), and then we end up with
class cast exception.
There is no workaround other than going against specification in code: define local home
interface to return instance of local business interface.
This simple session, which as far as I can see is exactly according to EJB 3 spec,
illustrates the problem, and does not work on JBoss 4.2.1.GA:
--
@javax.ejb.Stateless(name="Stateless")
@javax.ejb.LocalHome(StatelessHome.class)
@javax.ejb.Local({StatelessLocal.class})
public class StatelessBean implements StatelessLocal { public void ejbCreate() {} }
--
public interface StatelessLocal {}
--
public interface StatelessHome extends javax.ejb.EJBLocalHome
{ public StatelessLocal21 create() throws javax.ejb.CreateException;}
--
public interface StatelessLocal21 extends javax.ejb.EJBLocalObject, StatelessLocal {}
--
When home is looked up, and create is called, the result is:
java.lang.ClassCastException: $Proxy271 cannot be cast to StatelessLocal21
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira