Uploaded image for project: 'Hibernate ORM'
  1. HHH-12379

Add support for persistence_2_2.xsd and orm_2_2.xsd

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.3.0.CR1
    • Fix Version/s: 5.3.0.CR2
    • Component/s: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      When defining the persistence.xml and using the new persistence_2_2.xsd schema with version=2.2, the persistence units inside are not found by hibernate when creating the EntityManagerFactory.

      The issue seems to be that hibernate is not using the latest schema to validate the persistence.xml, as demonstrated by the following sample and stack trace:

      <?xml version="1.0" encoding="UTF-8" ?>
      <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                   http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
                   version="2.2">
      
          <persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
      
              <non-jta-data-source>jdbc/ExampleDS</non-jta-data-source>
      
              <class>com.example.test.Project</class>
      
          </persistence-unit>
      
      </persistence>
      

      Sample code:

      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      
      public class TestApp {
      
          public static void main(String args[]) {
      
              EntityManagerFactory emf = Persistence.createEntityManagerFactory("example");
          }
      }
      

      When running the following example I get the following error:

      Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named example
      	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
      	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      	at com.example.test.TestApp.main(TestApp.java:10)
      2018-03-11 20:15:34,010 DEBUG -- org.hibernate.jpa.HibernatePersistenceProvider --  Unable to create EntityManagerFactory {} javax.persistence.PersistenceException: Unable to locate persistence units
      	at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:93)
      	at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:69)
      	at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
      	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
      	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
      	at com.example.test.TestApp.main(TestApp.java:10)
      Caused by: javax.persistence.PersistenceException: Unrecognized persistence.xml version [2.2]
      	at org.hibernate.jpa.boot.internal.PersistenceXmlParser.validate(PersistenceXmlParser.java:491)
      	at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:445)
      	at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:247)
      	at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:240)
      	at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:234)
      	at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:71)
      	at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:89)
      	... 5 more
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: