Tasos p created TOMEE-3788:
------------------------------
Summary: Can't lookup ejb
Key: TOMEE-3788
URL: https://issues.apache.org/jira/browse/TOMEE-3788
Project: TomEE
Issue Type: Bug
Components: Examples and Documentation
Affects Versions: 8.0.5
Reporter: Tasos p
I have implemented a basic EJB Object in my code. Then I created a jar for this
ejb. The jar file contains:
# package containing the ejb classes (home interface/remote bean
interface/bean implementaion)
# 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?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)