users@glassfish.java.net

JPA possible in Glassfish v3 web services ?

From: <glassfish_at_javadesktop.org>
Date: Tue, 16 Mar 2010 01:15:31 PDT

Is JPA possible with Glassfish v3 web services or are there some known JPA web service examples for glassfish v3 somewhere?

I find that it always gives the exception shown below, when I do the following in a web service:

   @PersistenceUnit(unitName = "CustomerServicePersistenceUnit")
   private EntityManagerFactory emf;

then:

    emf.createEntityManager().find(....)

with persistence.xml as follows:

    <?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">
      <persistence-unit name="CustomerServicePersistenceUnit" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>tabs/TabsPool</jta-data-source>
        <properties>
          <property name="eclipselink.target-server" value="SunAS9"/>
          <property name="eclipselink.logging.level" value="FINEST"/>
        </properties>
      </persistence-unit>
    </persistence>

Here's what it does:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Unable to retrieve EntityManagerFactory for unitName CustomerServicePersistenceUnit
        at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:171)
        at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:102)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:240)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)
        at $Proxy29.getCustomerById(Unknown Source)
        at cstwsclient.Main.main(Main.java:14)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName CustomerServicePersistenceUnit
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:121)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:162)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.find(EntityManagerWrapper.java:309)
[Message sent by forum member 'dcam' (david_at_pastornet.net.au)]

http://forums.java.net/jive/thread.jspa?messageID=392108