openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Curtis <curti...@gmail.com>
Subject Multiple persistence.xml files causing runtime ehnahcement havoc
Date Fri, 13 Feb 2009 21:38:22 GMT

What should happen if I am running a runtime enhanced JSE application and
there are multiple persistence.xml files in my classpath?

I found today that in some cases when I have an empty persistence.xml and a
working persistence.xml file in my application's classpath, the enhancer
doesn't run on my entity classes. Below I documented the order of which
persistence.xml file 'wins' and ONLY the classes in that xml are enhanced.
Another thing to note is that OpenJPA did use the PU properties that I
specified in my 'working' xml(regardless of which xml is first in the
classpath). 

The most alarming part is that OpenJPA behaves different across releases.

The winner's classes are enhanced and the loser's classes aren't.
openjpa-1.1.0.jar: The first persistence.xml found in the classpath is used.
openjpa-1.2.0.jar: The last persistence.xml found in the classpath is used.
openjpa-2.0.0-SNAPSHOT.jar: The last persistence.xml found in the classpath
is used.

* Empty 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" version="1.0">    
</persistence>

* Working 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" version="1.0">    
    <persistence-unit name="jpa.enhancement"
transaction-type="RESOURCE_LOCAL">
        <!-- Enumerate each entity in the persistence unit -->
        <class>main.TestEntity</class>
        <properties>
                <!-- Configure DB connection -->                
                <property name="openjpa.ConnectionDriverName"
value="org.apache.commons.dbcp.BasicDataSource"/>
                <property name="openjpa.ConnectionProperties"
value="DriverClassName=com.mysql.jdbc.Driver,Url=jdbc:mysql://localhost/test,Username=root,Password=password"/>
                <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
        </properties>
    </persistence-unit>
</persistence>

-- 
View this message in context: http://n2.nabble.com/Multiple-persistence.xml-files-causing-runtime-ehnahcement-havoc-tp2323966p2323966.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Mime
View raw message