Hello,
I am having trouble setting up a resource for my web app. First, some
background...
I am using Tomcat 5.5 and OpenJPA 1.2.0. Everything is working fine in the
unmanaged fashion:
EntityManagerFactory emf = Persistence.createEntityManagerFactory(null);
EntityManager em = emf.createEntityManager();
Inspired by the OpenJPA manual at
http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/jpa_overview_emfactory.html,
JPA allows you to create and configure an EntityManagerFactory,
then store it in a Java Naming and Directory Interface (JNDI)
tree for later retrieval and use.
I would like to do something like this:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
EntityManagerFactory emf = (EntityManagerFactory) envCtx.lookup("emf");
I started off by reading
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html. From
what I can see, I need to create a resource with a custom factory. I also
think the resource can be a resource-env-ref since it does not need
authentication.
So I put this into my web.xml:
<resource-env-ref>
<resource-env-ref-name>emf</resource-env-ref-name>
<resource-env-ref-type>org.apache.openjpa.persistence.OpenJPAEntityManagerFactory</resource-env-ref-type>
</resource-env-ref>
With that,
EntityManagerFactory emf = (EntityManagerFactory) envCtx.lookup("emf");
throws a NamingException (as I would expect, since I had not yet
configured the resource itself), "Cannot create resource instance",
org.apache.naming.factory.ResourceEnvFactory.getObjectInstance(ResourceEnvFactory.java:113)
So then I added a META-INF/context.xml like this:
<context>
<resource
name="emf" auth="Container"
type="org.apache.openjpa.persistence.OpenJPAEntityManagerFactory"
factory="sh.helloworld.testing.EMFFactory"
/>
</context>
EMFFactory is a class I wrote that implements
javax.naming.spi.ObjectFactory, which is then placed in my WEB-INF/classes
path.
Unfortunately, I still receive the same NamingException, thrown by
ResourceEnvFactory. I was hoping to at least get an exception from my
custom factory. The fact that tomcat is still calling the
ResourceEnvFactory is why I thought that my question is for the Tomcat
mailing list and not the OpenJPA list.
Thanks in advance for any help!
Derek
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org