EJB 3, dependency injection and inheritance

Discussions

EJB programming & troubleshooting: EJB 3, dependency injection and inheritance

  1. EJB 3, dependency injection and inheritance (2 messages)

    I am trying out EJB 3.0.  I use RAD 8 and WebSphere application server 7.  I created an Session Bean let’s call it TopSessionEJB and injected a datasoure into that bean like:

    @Resource(name="myDataSource")
    private  javax.sql.DataSource defaultDataSource;

    I update my ibm-ejb-jar-bind.xml and map the datasource to the real jndi data source name:

    <session name="TopSessionEJB ">
      <resource-ref name="myDataSource"
       binding-name="jdbc/myRealDB">
      </resource-ref>
     </session>

    I call the this EJB from the servlet and everything works fine.  

    Now if I make a subclass of TopSessionEJB, let’s call it MySubClassEJB. I deploy this updated EAR on the server, things are fine.  I try to access my old Servlet from the browser which in turn calls my old TopSessionEJB, I get error in my server logs, complaining that I did not provide any resource reference for my  MySubClassEJB's myDataSource.

    Caused by:
    com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding could not be found for the following resource references [myDataSource], defined for the MySubClassEJB component.
    at com.ibm.wsspi.injectionengine.InjectionProcessor.collectInjectionNBindingData(

    One would think I just need another entry in the ibm-ejb-jar-bind.xml for this subclass MySubClassEJB  but if I try to do that I get RAD error that I am creating a resource reference for something that does not exist.

    So the question is how do you inject a database resource-reference in the your base EJB and then inherit that datasource in all of your sub-classes.

    I would appreciate if someone could help.

    Thanks

  2. I kind of answered my own question.  EJB 3.0 does not allow inheritance between two session beans.  I confused EJB 3.1 specs which allow the session beans to inherit from each other.  So the issue that I was getting was probably a way of WebSphere-7 telling me that somthing is not right. 

  3. I’m about to take part[ Go to top ]

    I’m about to take part of a project and I’m very interested in this process. And I can’t seem to find any information, so far. - Scott Sohr