views:

783

answers:

1

I am trying to get JPA (Toplink) configured to run in Jetty being run from the maven plugin and am getting a javax.naming.NameNotFoundException. The specifics.

web.xml:

<persistence-unit-ref>
    <persistence-unit-ref-name>persistence/mod</persistence-unit-ref-name>
    <persistence-unit-name>ModPU</persistence-unit-name>
</persistence-unit-ref>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/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"&gt;
  <persistence-unit name="ModPU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <properties>
      <property name="toplink.jdbc.url" value="jdbc:mysql://localhost/mod"/>
      <property name="toplink.jdbc.user" value="user"/>
      <property name="toplink.jdbc.driver" value="org.gjt.mm.mysql.Driver"/>
      <property name="toplink.jdbc.password" value="pass"/>
      <property name="toplink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

code:

@PersistenceUnit(unitName = "ModPU")
EntityManagerFactory emf;

error when referencing emf:

Caused by: javax.naming.NameNotFoundException; remaining name 'persistence/ugc'
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:634)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:665)
    at org.mortbay.naming.NamingContext.lookup(NamingContext.java:680)
    at org.mortbay.naming.java.javaRootURLContext.lookup(javaRootURLContext.java:112)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.sun.jersey.server.impl.container.servlet.ThreadLocalNamedInvoker.invoke(ThreadLocalNamedInvoker.java:65)
    ... 37 more
A: 

I believe the line:

<persistence-unit-ref-name>persistence/mod</persistence-unit-ref-name>

in your web.xml is not needed and should be removed.

Rich Kroll