3 Replies Latest reply on Jul 7, 2008 7:42 AM by wernic

    JPA in a plain webapp

    wernic

      I want to use JPA in a plain webapp (no EJB3).

      META-INF/persistence.xml (goes to the WEB-INF/classes/META-INF/persistence.xml):

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence 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"
       version="1.0">
      
       <persistence-unit name="testpu" transaction-type="JTA">
       <jta-data-source>java:test</jta-data-source>
       </persistence-unit>
      </persistence>


      Next I want to export PU to the JNDI tree.

      web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      
       <persistence-unit-ref>
       <persistence-unit-ref-name>persistence/test</persistence-unit-ref-name>
       <persistence-unit-name>testpu</persistence-unit-name>
       </persistence-unit-ref>
      </web-app>


      While starting exception is thrown:

      09:43:47,887 INFO [TomcatDeployment] deploy, ctxPath=/test, vfsUrl=test.war
      09:43:47,910 WARN [PersistenceUnitHandler] Could not find PU dependency for persistence.units:unitName=testpu. Waiting for dependency to resolve
      09:43:47,922 ERROR [TomcatDeployment] ENC setup failed
      java.lang.RuntimeException: Failed to locate <persistence-unit-ref> of unit name: testpu for test.war
       at org.jboss.injection.PuEncInjector.inject(PuEncInjector.java:62)
       at org.jboss.web.tomcat.service.TomcatInjectionContainer.populateEnc(TomcatInjectionContainer.java:268)
       ...


      Any thoughts?