0 Replies Latest reply on Mar 5, 2008 12:24 PM by Ben Walker

    Inject EJB 2.1 Entity Home into EJB 3.0 session beans using

    Ben Walker Newbie

      Hi,

      Has anyone been able to inject a 2.1 entity bean home into 3.0 session bean using the @EJB annotation in jboss-5.0.0.Beta4?

      I have tried the following (fairly sure it should work according to EJB3 spec)

      Session Fragment: -

      @Stateless(name="ExampleService")
      @Local(ExampleService.class)
      @Remote(ExampleServiceRemote.class)
      @TransactionAttribute(REQUIRED)
      public class ExampleServiceBean implements ExampleService,ExampleServiceRemote,Serializable {
      
       private static final long serialVersionUID = -7533521006618484580L;
      
       @EJB
       private Example21EntityHome example21EntityHome;
      
       private static Logger logger = Logger.getLogger(ExampleServiceBean.class);
      
       /**
       * Does what ever you tell it too
       * @param whatToDo request text
       * @return string response text
       */
       public String doSomething(String whatToDo) {
      
      
       String doing = "doing " + whatToDo;
      
       try {
       example21EntityHome.create(doing);
       } catch (CreateException e) {
      
       logger.error("Unable to create 2.1 entity bean",e);
       }
      
       logger.info(doing);
       return doing;
      
       }
      
      
      
      }


      Entity Fragment : -
      public abstract class Example21EntityBean extends EntityAdapter implements Serializable {
      
       public abstract Integer getPk();
      
       public abstract void setPk(Integer pk);
      
       public abstract String getData();
      
       public abstract void setData(String data);
      
       public Integer ejbCreate(String data) throws CreateException {
       // dummy, pk set by auto-generated-pk
       setPk(0);
       setData(data);
       return null;
       }
      
       public void ejbPostCreate(String data) {
       // empty implementation
      
       }
      }


      2.1 Entity Bean Deployment Descriptor
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
       <display-name>Example 21 Legacy</display-name>
       <enterprise-beans>
       <entity>
       <ejb-name>Example21Entity</ejb-name>
       <local-home>com.entitybean21.Example21EntityHome</local-home>
       <local>com.entitybean21.Example21Entity</local>
       <ejb-class>com.entitybean21.Example21EntityBean</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Integer</prim-key-class>
       <reentrant>false</reentrant>
       <abstract-schema-name>Example21Entity</abstract-schema-name>
       <cmp-field>
       <description>This is the PK</description>
       <field-name>pk</field-name>
       </cmp-field>
       <cmp-field>
       <field-name>data</field-name>
       </cmp-field>
       <primkey-field>pk</primkey-field>
       </entity>
       </enterprise-beans>
       <assembly-descriptor>
       <container-transaction>
       <method>
       <ejb-name>Example21Entity</ejb-name>
       <method-name>create</method-name>
       </method>
       <trans-attribute>Required</trans-attribute>
       </container-transaction>
       <container-transaction>
       <method>
       <ejb-name>Example21Entity</ejb-name>
       <method-name>*</method-name>
       </method>
       <trans-attribute>Supports</trans-attribute>
       </container-transaction>
       </assembly-descriptor>
      </ejb-jar>
      


      However, on deployment I get the following stack trace: -
      17:13:58,517 ERROR [ProfileServiceBootstrap] Failed to load profile: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
      
      *** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
      
      jboss.j2ee:ear=example.ear,jar=example-ejb.jar,name=ExampleService,service=EJB3
       -> <UNKNOWN>{Described:** UNRESOLVED Demands 'Class:com.entitybean21.Example21EntityHome **}
       -> <UNKNOWN>{Described:** UNRESOLVED Demands 'jboss.ejb:service=EJBTimerService **}
      
      
      *** CONTEXTS IN ERROR: Name -> Error
      
      <UNKNOWN> -> ** UNRESOLVED Demands 'jboss.ejb:service=EJBTimerService **
      


      NB Packaged as two ejb jar files in the same ear to get around issue posted @ http://www.jboss.org/?module=bb&op=viewtopic&t=103268

      Has anyone tried to do something similar? Is this supported functionality?

      Thanks
      Ben