Re: ClassCastException on JNDI lookup
On Jul 9, 2008, at 2:34 AM, chawax wrote: Yes, that was the problem ! I replaced local with business-local and everything works perfect now ! Thanks a lot David. Looks like we did have some validation logic in there for checking usage of the remote and local elements, but it only kicked in if you also specify the related home or local-home interface. I've fixed that and also made the code check for this very specific mistake and issue an appropriate message. We now have about 44 different error messages we're prepared to issue in regards to misuse of either the home, remote, local-home, local, business- local and business-remote elements. That should be enough :) -David David Blevins wrote: The issue is local must refer to interfaces that extend javax.ejb.EJBLocalObject, i.e. the old style EJB 2.x interfaces. You just need to update your descriptor to use the business-local element instead as in: session ejb-nameEmployeeServiceBean/ejb-name business-localt4.core.employee.EmployeeServiceLocal/business- local ejb-classt4.core.employee.EmployeeServiceBean/ejb-class session-typeStateless/session-type transaction-typeContainer/transaction-type /session That should fix the issue. Alternatively, you can let the annotation do the work and leave EmployeeServiceLocal out of your ejb-jar.xml entirely. -- View this message in context: http://www.nabble.com/ClassCastException-on-JNDI-lookup-tp18342366p18357709.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: ClassCastException on JNDI lookup
Hi, I tried to replicate your class hierarchy with the simple-stateless example that comes with OpenEJB, and I wasn't able to reproduce your problem. I've popped my code up http://www.jrg.me.uk/examples.zip - perhaps you could have a look and let me know if my class hierarchy matches yours, or if there is anything I've missed in trying to reproduce the problem? (Or if you have some code you can share that I can try running that would be great too). Could you also let me know which version of OpenEJB you're using, I've assumed you're using the released 3.0, and I've tested with both that and the latest from trunk. Thanks Jon chawax wrote: 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-nameEmployeeServiceBean/ejb-name localt4.core.employee.EmployeeServiceLocal/local ejb-classt4.core.employee.EmployeeServiceBean/ejb-class session-typeStateless/session-type transaction-typeContainer/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 !
Re: ClassCastException on JNDI lookup
On Jul 8, 2008, at 8:47 AM, chawax wrote: And two interfaces, generated everytime too : - @javax.ejb.Local interface EmployeeServiceLocal extends EmployeeService - interface EmployeeService [...] I also have a ejb-jar.xml file with EJB defined as following : session ejb-nameEmployeeServiceBean/ejb-name localt4.core.employee.EmployeeServiceLocal/local ejb-classt4.core.employee.EmployeeServiceBean/ejb-class session-typeStateless/session-type transaction-typeContainer/transaction-type /session The issue is local must refer to interfaces that extend javax.ejb.EJBLocalObject, i.e. the old style EJB 2.x interfaces. You just need to update your descriptor to use the business-local element instead as in: session ejb-nameEmployeeServiceBean/ejb-name business-localt4.core.employee.EmployeeServiceLocal/business- local ejb-classt4.core.employee.EmployeeServiceBean/ejb-class session-typeStateless/session-type transaction-typeContainer/transaction-type /session That should fix the issue. Alternatively, you can let the annotation do the work and leave EmployeeServiceLocal out of your ejb-jar.xml entirely. I'm surprised you didn't get a validation failure. We aggressively check for all sorts of possible mistakes, such as using business- local where local should be used or using local where local- home should be used, etc. You just happened to find one we didn't check for :) Looks like a pretty important one too! We will definitely add it for the next release. Thanks in advance for your help ;) No problem! 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 ! Thank you very much for the positive feedback, we definitely appreciate it. -David
Re: ClassCastException on JNDI lookup
Yes, that was the problem ! I replaced local with business-local and everything works perfect now ! Thanks a lot David. Olivier David Blevins wrote: The issue is local must refer to interfaces that extend javax.ejb.EJBLocalObject, i.e. the old style EJB 2.x interfaces. You just need to update your descriptor to use the business-local element instead as in: session ejb-nameEmployeeServiceBean/ejb-name business-localt4.core.employee.EmployeeServiceLocal/business- local ejb-classt4.core.employee.EmployeeServiceBean/ejb-class session-typeStateless/session-type transaction-typeContainer/transaction-type /session That should fix the issue. Alternatively, you can let the annotation do the work and leave EmployeeServiceLocal out of your ejb-jar.xml entirely. -- View this message in context: http://www.nabble.com/ClassCastException-on-JNDI-lookup-tp18342366p18357709.html Sent from the OpenEJB User mailing list archive at Nabble.com.
ClassCastException on JNDI lookup
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-nameEmployeeServiceBean/ejb-name localt4.core.employee.EmployeeServiceLocal/local ejb-classt4.core.employee.EmployeeServiceBean/ejb-class session-typeStateless/session-type transaction-typeContainer/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.