Hi,

I try to use OpenEJB to run unit tests within a Maven project. Part of the
code of this project is generated by AndroMDA MDA framework.

For each EJB session bean, four classes are generated, to separate code
generated once from code generated at each Maven install, to share code
between local and remote EJB, etc ...

For example for an EmployeeService local EJB I have the following classes :

One implementation class, generated once, where I can write business code :
- class EmployeeServiceBean extends  EmployeeServiceBase implements
EmployeeServiceLocal

One abstract base class, generated everytime I run mvn install :
- abstract class EmployeeServiceBase implements EmployeeService

And two interfaces, generated everytime too :
- @javax.ejb.Local interface EmployeeServiceLocal extends EmployeeService
- interface EmployeeService

All public methods for a stateless EJB are declared in EmployeeServiceLocal
interface, the other interface is supposed to define getter and setter
methods for attributes of stateful session beans.

I also have a ejb-jar.xml file with EJB defined as following :

<session>
    <ejb-name>EmployeeServiceBean</ejb-name>
    <local>t4.core.employee.EmployeeServiceLocal</local>
    <ejb-class>t4.core.employee.EmployeeServiceBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>
</session>

In a TestNG test class, I have the following code looking for the EJB
session bean from its JNDI name :

EmployeeServiceLocal employeeService = 
    (EmployeeServiceLocal)
getInitialContext().lookup("EmployeeServiceBean/Local");

OpenEJB retrieves the EJB but I have a ClassCastException. I expected the
EJB to be EmployeeServiceLocal typed (as it is the case in ejb-jar.xml), but
it is EmployeeService typed ! It looks like OpenEJB doesn't retrieve
interface of the implementation class, but interface from the base class. Is
it something intended or is it a bug ? 

Thanks in advance for your help ;)

And congratulations for the good job made on OpenEJB. I tried to use other
embedded containers (JBoss Embedded, Glassfish embedded, EJB3Unit, ...) and
met so many bugs I could not make them work. I am not far to succeed with
Open EJB !
-- 
View this message in context: 
http://www.nabble.com/ClassCastException-on-JNDI-lookup-tp18342366p18342366.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to