OpenJPA
  1. OpenJPA
  2. OPENJPA-9

PCEnhancer not processing multiple PU's defined within a single persistence.xml file

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.0
    • Component/s: jpa
    • Labels:
      None

      Description

      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.

        Activity

        Hide
        Patrick Linskey added a comment -

        I changed a number of other command-line scripts to loop over multiple PUs as well. I have not exhaustively tested all the command-line scripts.

        Show
        Patrick Linskey added a comment - I changed a number of other command-line scripts to loop over multiple PUs as well. I have not exhaustively tested all the command-line scripts.
        Hide
        Michael Spiro added a comment -

        Is this issue really fixed? I'm using the PCEnhancerTask with Ant and OpenJPA version 2.1.0 and the bug is still there. This line:

        PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, loader);

        (Class PersistenceProductDerivation , line 525) seems to be the point where it begins to go wrong. This following method (beginning in the line 554) generates an internal list of all persistence units, but returns only one of them losing infromation about the rest:

        private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser,
        List<URL> urls, String name, ClassLoader loader)
        throws IOException {
        List<PersistenceUnitInfoImpl> pinfos = new ArrayList<PersistenceUnitInfoImpl>();
        for (URL url : urls)

        { parser.parse(url); pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults()); }

        return findUnit(pinfos, name, loader);
        }

        Show
        Michael Spiro added a comment - Is this issue really fixed? I'm using the PCEnhancerTask with Ant and OpenJPA version 2.1.0 and the bug is still there. This line: PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, loader); (Class PersistenceProductDerivation , line 525) seems to be the point where it begins to go wrong. This following method (beginning in the line 554) generates an internal list of all persistence units, but returns only one of them losing infromation about the rest: private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser, List<URL> urls, String name, ClassLoader loader) throws IOException { List<PersistenceUnitInfoImpl> pinfos = new ArrayList<PersistenceUnitInfoImpl>(); for (URL url : urls) { parser.parse(url); pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults()); } return findUnit(pinfos, name, loader); }

          People

          • Assignee:
            Unassigned
            Reporter:
            Kevin Sutter
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development