users@glassfish.java.net

Re: Accessing Persistence Unit from a WAR in an EAR - not working

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Fri, 13 Jul 2007 00:03:21 -0700

Hi,

Entities are not EJBs. You need to remove the ref in the application.xml.

Also, most probably "jndi:/brookDbResource" is not the right resource JNDI name.

Regards,
-marina


glassfish_at_javadesktop.org wrote:
> Hi everyone,
>
> I've read everything I could on how to package to a PU, and I simply cannot figure out what I am doing wrong.
>
> In my servlet (Test.java extends HttpServlet) I have two injections:
>
> @PersistenceUnit(unitName="bpu")
> EntityManagerFactory factory;
>
> @Resource
> UserTransaction transaction;
>
> I need to manage transactions from here. The servlet is in a WAR file (DoWeb.war) which itself is in the top-level of an EAR file (DoApplication.ear). The PU is together with the entities for the application, in lib/DoEntities.jar.
>
> The PU is in META-INF/persistence.xml.
>
> I simply cannot make the verifier or the app server (glassfish) convince that the PU should be visible by the Servlet file.
>
> When I run the verifier I get the following message: There is no unique persistence unit found by name [ bpu ] in the scope of this component.
> Persistence units that are visible to this component are [ ].
>
> I know the PU is correct because a token ejb in DoEntity.jar is able to see the PU (it fails if I cause a small unitName mismatch and works when I fix it).
>
> The only thing that is not textbook is that DoEntities actually an ejb jar (with a TokenEjb in addition to the entities and the PU). the reason for this is that IntelliJ has a limitation where it doesn't support <java> entries in a J2EE app. I fixed that by hand to check, however, and it doesn't help.
>
> Can someone help?
>
> More complete details: the application (which i tore down to its bare essentials for debugging purposes) looks like this:
>
> DoApplication.ear:
> +META-INF/MANIFEST.MF
> +lib/DoEntity.jar
> +DoWeb.war
> +META-INF/application.xml
> +META-INF/sun-application.xml
>
> DoEntity.jar
> +META-INF/MANIFEST.MF
> +brook/
> +brook/todo/
> +brook/todo/entity/
> +brook/todo/entity/EmailReminder.class
> +brook/todo/entity/Item.class
> +brook/todo/entity/Privacy.class
> +brook/todo/entity/User.class
> +TokenEjb.class
> +META-INF/persistence.xml
>
> DoWeb.war:
> +META-INF/MANIFEST.MF
> +WEB-INF/classes/
> +WEB-INF/classes/brook/
> +WEB-INF/classes/brook/todo/
> +WEB-INF/classes/brook/todo/web/
> +WEB-INF/classes/brook/todo/web/servlet/
> +WEB-INF/classes/brook/todo/web/servlet/Test.class
> +WEB-INF/
> +WEB-INF/sun-web.xml
> +WEB-INF/web.xml
>
> 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">
> <persistence-unit name="bpu">
> <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
> <jta-data-source>jndi:/brookDbResource</jta-data-source>
> <properties>
> <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
> </properties>
> </persistence-unit>
> </persistence>
>
> Application.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <application 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/application_5.xsd"
> version="5">
> <display-name>DoApp</display-name>
> <module id="DoEntity">
> <ejb>lib/DoEntity.jar</ejb>
> </module>
> <module id="DoWeb">
> <web>
> <web-uri>DoWeb.war</web-uri>
> <context-root>DoWeb</context-root>
> </web>
> </module>
>
> </application>
> [Message sent by forum member 'br_31' (br_31)]
>
> http://forums.java.net/jive/thread.jspa?messageID=226509
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>