OpenJPA
  1. OpenJPA
  2. OPENJPA-1203

JPA2 - createEMF should return null for unhandled PUs

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.0-M3
    • Component/s: docs
    • Labels:
      None

      Description

      JPA2 spec section 9.2 states - "If a provider does not qualify as the provider for the named persistence unit, it must return null when createEntityManagerFactory is invoked on it."
      But OpenJPA is throwing exceptions for all failure cases...
      For now, we'll keep the 1.x behavior, but may need to revisit this when we start running the JPA2 TCK.

        Issue Links

          Activity

          Show
          Donald Woods added a comment - Also see discussion thread http://n2.nabble.com/JPA2---When-should-createEMF%28%29-return-an-Exception-vs.-NULL--tp3312130p3312130.html
          Hide
          Donald Woods added a comment -

          Doc this as an OpenJPA behavior...

          Show
          Donald Woods added a comment - Doc this as an OpenJPA behavior...
          Hide
          Donald Woods added a comment - - edited

          View r820390 of the geronimo-jpa_2.0_spec code for the implemented createEMF() behavior for handling exceptions -
          http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java?view=markup&pathrev=820390

          Basically, even if a provider returns an exception, we'll still give any other provider on the classpath a chance, as required by the JPA 2.0 spec.
          If one exception is returned and no provider can return a EMF, then that exception is returned as the cause within a PersistenceException, so apps can use getCause() to determine the provider returned failure.
          If more than one exception is returned and no provider can return a EMF, then the exceptions are added to the end of the PersistenceException message and no cause will be set.
          Even if one or more providers return an exception, if a provider does return a EMF, then all exceptions will be discarded and the EMF will be returned to the caller.
          If no exceptions occur and no EMF can be returned, then a PersistenceException will be thrown with a generic message and list of providers discovered.

          Show
          Donald Woods added a comment - - edited View r820390 of the geronimo-jpa_2.0_spec code for the implemented createEMF() behavior for handling exceptions - http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java?view=markup&pathrev=820390 Basically, even if a provider returns an exception, we'll still give any other provider on the classpath a chance, as required by the JPA 2.0 spec. If one exception is returned and no provider can return a EMF, then that exception is returned as the cause within a PersistenceException, so apps can use getCause() to determine the provider returned failure. If more than one exception is returned and no provider can return a EMF, then the exceptions are added to the end of the PersistenceException message and no cause will be set. Even if one or more providers return an exception, if a provider does return a EMF, then all exceptions will be discarded and the EMF will be returned to the caller. If no exceptions occur and no EMF can be returned, then a PersistenceException will be thrown with a generic message and list of providers discovered.
          Hide
          Donald Woods added a comment -

          mentioned in Migration section of docs using r822006

          Show
          Donald Woods added a comment - mentioned in Migration section of docs using r822006

            People

            • Assignee:
              Donald Woods
              Reporter:
              Donald Woods
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development