geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: Container-managed JPA in pure WAR with JNDI
Date Fri, 12 Feb 2010 18:20:02 GMT
Geronimo doesn't use jndi for the datasources in persistence.xml.  You  
don't need to configure resource-refs for the datasources.  You do  
need to make sure they are in ancestor plugins to the app and that you  
use the name from the datasource configuration.  In this case I think  
that would be
<jta-data-source>SystemDatabase</jta-data-source>

In my experience, at least with derby, you need both jta and non-jta  
datasource.  I guess if you aren't using jta transactions at all you  
might be able to use just a non-jta-data-source, but I haven't tried  
this.

thanks
david jencks

On Feb 12, 2010, at 6:53 AM, Alexandros Karypidis wrote:

> Hello,
>
> My scenario is this:
>
> I have a library with entities (as in @Entity objects) containing my  
> domain model. I want to declare a container-managed persistence unit  
> in a standalone WAR (not EAR), using that library (the  
> persistence.xml must NOT be in the library, but the WAR). So, I  
> proceed as follows (this is valid as far as I know, base on J2EE5  
> specs):
>
> 1) I have declared a data source in geronimo-web.xml and web.xml  
> (see below for file contents).
> 2) I put my library (as a jar) in my WAR's WEB-INF/lib and added a  
> WEB-INF/classes/META-INF/persistence.xml in the WAR (see below for  
> file contents).
>
> Deployment after performing step (1) worked and I could see the data  
> source registered in the console.
>
> Deployment after performing step (2) fails; from what I understand  
> from the error (see below), geronimo claims the data-source from  
> step (1) does not exist. I assume that geronimo tries to create the  
> persistence context prior to registering the data source? (i.e. it  
> processes persistence.xml prior to apply the configuration from  
> web.xml and geronimo-web.xml).
>
> What do I need to configure this properly. My deployment descriptors  
> and the error trace follow:
>
> 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="appPersistenceUnit" transaction-type="JTA">
>        <jta-data-source>jdbc/AppDataSource</jta-data-source>
>        <jar-file>app-entities.jar</jar-file>
>    </persistence-unit>
> </persistence>
>
>
> web.xml
> -------------------------------------------------------------------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app
>    xmlns="http://java.sun.com/xml/ns/j2ee"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="
>        http://java.sun.com/xml/ns/j2ee
>        http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
>    version="2.4">
>
>    <display-name>App</display-name>
>
>    <!-- Unrelated Spring contextListener and Wicket filter  
> configuration here
>    have been supresed -->
>
>    <resource-ref>
>        <res-ref-name>jdbc/AppDataSource</res-ref-name>
>        <res-type>javax.sql.DataSource</res-type>
>        <res-auth>Container</res-auth>
>        <res-sharing-scope>Shareable</res-sharing-scope>
>    </resource-ref>
> <!--
>    Ultimately I want to do this, but I can't get persistence.xml to  
> work...
>    <persistence-unit-ref>
>        <persistence-unit-ref-name>persistence/appPersistenceUnit</ 
> persistence-unit-ref-name>
>        <persistence-unit-name>appPersistenceUnit</persistence-unit- 
> name>
>    </persistence-unit-ref>
> -->
> </web-app>
>
>
> geronimo-web.xml
> -------------------------------------------------------------------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
>    xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
>    xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
>    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
>
>    <sys:environment>
>        <sys:moduleId>
>            <sys:groupId>app</sys:groupId>
>            <sys:artifactId>app-frontend</sys:artifactId>
>            <sys:version>0.0.1</sys:version>
>            <sys:type>car</sys:type>
>        </sys:moduleId>
>        <sys:dependencies>
>            <!-- Need the embedded Derby -->
>            <sys:dependency>
>                <sys:groupId>org.apache.geronimo.configs</sys:groupId>
>                <sys:artifactId>
>                    system-database
>                </sys:artifactId>
>            </sys:dependency>
>        </sys:dependencies>
>    </sys:environment>
>
>    <context-root>/app</context-root>
>
>    <!-- Ultimately, I want to register the PU in JNDI,
>    but persistence.xml does not work
>    <naming:persistence-unit-ref>
>        <naming:persistence-unit-ref-name>persistence/ 
> appPersistenceUnit</naming:persistence-unit-ref-name>
>        <naming:persistence-unit-name>persistence/appPersistenceUnit</ 
> naming:persistence-unit-name>
>    </naming:persistence-unit-ref>
>    -->
>
>    <naming:resource-ref>
>        <naming:ref-name>jdbc/AppDataSource</naming:ref-name>
>        <naming:resource-link>SystemDatasource</naming:resource-link>
>    </naming:resource-ref>
> </web-app>
>
> __________________________________________________
> Χρησιμοποιείτε Yahoo!;
> Βαρεθήκατε τα ενοχλητικά μηνύματα  
> (spam);   Το Yahoo! Mail διαθέτει την καλύτερη  
> δυνατή προστασία κατά των  
> ενοχλητικών μηνυμάτων
> http://mail.yahoo.gr


Mime
View raw message