[ 
https://issues.apache.org/jira/browse/OPENJPA-2226?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Manuel Meyer updated OPENJPA-2226:
----------------------------------

             Priority: Major  (was: Minor)
          Description: 
When multiple persistence-units are defined in the persistence.xml, only the 
first one is examined when looking for classes to enhance when using the 
automatic runtime enhancement (e.g., using the "-javaagent:openjpa.jar" 
argument). So if the project uses the following persistence.xml: 

<persistence xmlns="http://java.sun.com/xml/ns/persistence"; version="1.0"> 
    <persistence-unit name="unit1" transaction-type="RESOURCE_LOCAL"> 
        <class>unit1.SomeClass</class> 
    </persistence-unit> 
    <persistence-unit name="unit2" transaction-type="RESOURCE_LOCAL"> 
        <class>unit2.SomeClass</class> 
    </persistence-unit> 
</persistence> 

In this example, when unit1.SomeClass is loaded, it will be enhanced, but 
unit2.SomeClass won't ever be enhanced. 

The only workaround is to list all of your persistent classes in an initial 
entry in the persistence-unit. 

  was:
>From a discussion with Patrick on the dev mailing list...

=========================================================================
Me:  According to the JPA spec, we can define multiple persistence-units in a 
single persistence.xml file.  But, when I try to use this persistence.xml file 
as input to the PCEnhancer, it is only processing the first persistence-unit 
that is defined.  I traced through the code and found that this is the case.  
When the persistence.xml file is processed, a "null" name is passed in for the 
desired persistence-unit (in the ConfigurationProviderImpl.load method) and, 
thus, only the first one defined is returned and used by the PCEnhancer.

Patrick:  IMO, the correct behavior should be:

- PCEnhancer run with no arguments should load all the PUs in the
classpath, find the OpenJPA (or unspecified) PUs, and run against all
the classes defined by those PUs (including auto-scanning for PUs so
configured).

- The developer should not need to specify META-INF/persistence.xml when
invoking the PCEnhancer.

- We may want to provide a means to specify specific PUs to process. For
example:

 java ...PCEnhancer -p META-INF/persistence.xml#foo

or maybe just

 java ...PCEnhancer -p #foo

for shorthand.

Regardless, the current behavior seems wrong, and it seems that the best
initial change would be to make PCEnhancer load all the PUs (the first
bullet above), which means manually loading the META-INF/persistence.xml
resources and finding the ones that are OpenJPA PUs, rather than relying
on the javax.persistence.Persistence helper method to load them.
=========================================================================

Writing this bug report so as not to lose track of this problem.


    Affects Version/s: 2.0.1
                       2.2.0
    
> CLONE - PCEnhancer not processing multiple PU's defined within a single 
> persistence.xml file
> --------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2226
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2226
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.0.1, 2.2.0
>            Reporter: Manuel Meyer
>
> When multiple persistence-units are defined in the persistence.xml, only the 
> first one is examined when looking for classes to enhance when using the 
> automatic runtime enhancement (e.g., using the "-javaagent:openjpa.jar" 
> argument). So if the project uses the following persistence.xml: 
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"; version="1.0"> 
>     <persistence-unit name="unit1" transaction-type="RESOURCE_LOCAL"> 
>         <class>unit1.SomeClass</class> 
>     </persistence-unit> 
>     <persistence-unit name="unit2" transaction-type="RESOURCE_LOCAL"> 
>         <class>unit2.SomeClass</class> 
>     </persistence-unit> 
> </persistence> 
> In this example, when unit1.SomeClass is loaded, it will be enhanced, but 
> unit2.SomeClass won't ever be enhanced. 
> The only workaround is to list all of your persistent classes in an initial 
> entry in the persistence-unit. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to