tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chan Kelwin Hillary <ckel...@gmail.com>
Subject Lookup EntityManager from Stateless EJB Session Bean
Date Tue, 28 Jul 2009 20:44:02 GMT
Hi,
I have a stateless EJB Session bean that successfully instantiates the
EntityManger using the @PersistenceContext annotation. However, due to an
issue, I need to get the EntityManager by lookup instead. I've tried the
code below in the stateless session bean but it is giving me the error "Name
Persistence is not bound in this Context". I've also placed
the eclipselink.jar file into the %TOMCAT%\lib directory.

try {
    Context context = new InitialContext();
    em = (javax.persistence.EntityManager) context.lookup("Persistence");
} catch (NamingException e) {
    System.out.println(e.getExplanation());
}

persistence.xml
===================
<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="Persistence">
    <provider>
      org.eclipse.persistence.jpa.PersistenceProvider
    </provider>
    <jta-data-source>
      java:openejb/Connector/Default JDBC Database
    </jta-data-source>
    <class>
      com.testejb.model.ejb.dn.Dept
    </class>
    <properties>
      <property name="eclipselink.target-database" value="Oracle10g"/>
    </properties>
  </persistence-unit>
</persistence>

I am running this on Tomcat-6.0.20 (extracted from the zip file instead of
the executable) and the embedded OpenEJB. Can this be done? What am I
missing?

Thanks.


-- 
Best regards,

Chan Kelwin

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message