Uploaded image for project: 'TomEE'
  1. TomEE
  2. TOMEE-3788

Can't lookup ejb

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • 8.0.5
    • None
    • Important

    Description

      I have implemented a basic EJB Object in my code. Then I created a jar for this ejb. The jar file contains:

      1. package containing the ejb classes (home interface/remote bean interface/bean implementaion)
      2. META-INF folder containing the ejb-jar.xml

      ejb-jar.xml
       
      {{<?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>NewTransactionEjb</display-name>
      <enterprise-beans>
      <session>
      <display-name>NewTransactionEjb</display-name>
      <ejb-name>NewTransactionEjb</ejb-name>
      <home>gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome</home>
      <remote>gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjb</remote>
      <ejb-class>gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      </session>
      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>
      <method>
      <ejb-name>NewTransactionEjb</ejb-name>
      <method-name>*</method-name>
      </method>
      <trans-attribute>NotSupported</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>}}

      Then I deployed the EJB by placing the jar in webapps folder and from the server logs it seems to have been deployed successfully. But when I try to reference the ejb from my code I get error. Code:
       
      {{Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory"); InitialContext context = new InitialContext(p);
      ejbHome = (EJBHome) context.lookup("java:global/NewTransactionEjb/NewTransactionEjb");}}

      I have used "java:global/NewTransactionEjb/NewTransactionEjb" because upon ejb deployment I see this line in the server logs:
       
      03-Sep-2021 17:31:23.628 INFO [Catalina-utility-1] org.apache.openejb.assembler.classic.JndiBuilder.bind Jndi(name=global/NewTransactionEjb/NewTransactionEjb!gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome) --> Ejb(deployment-id=NewTransactionEjb)

      In the execution it seems the the above code is working and it retrieves the EJBHome, but when I try to cast it to my own home interface class it fails with the following error:
       
      {{java.lang.ClassCastException: com.sun.proxy.$Proxy362 cannot be cast to
      gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome}}

      What am I doing wrong?

      Attachments

        Activity

          People

            Unassigned Unassigned
            tasos121 Tasos p
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: