| Our project has two persistence.xml files:
- core/target/test-classes/META-INF/persistence.xml
- core/target/classes/META-INF/persistence.xml
with persistence name "vtregistry" in both. When running a JUnit test with Hibernate 5.2.4.Final, the main version is being returned which causes the tests to fail. Logs indicate that both persistence.xml files are found on the class path, with the test version first as expected when running a JUnit test.
In Hibernate 5.2.2.Final the test version is correctly returned and the tests succeed. If the persistence.xml file in main is removed so that only the test version is in the class path when the tests are executed, the tests run successfully in 5.2.4.Final. The problem seems to be related to the switch from ArrayList to ConcurrentHashMap in PersistenceXmlParser.java.
parsePersistenceXml is called to process the test-classes/META-INF persistence.xml file and returns a Map entry for this test version with key vtregistry, which is added to the persistenceUnits Map in doResolve via persistenceUnits.putAll. parsePersistenceXml is then called to process the classes/META-INF persistence.xml file and returns a Map entry for this main version with the same key (vtregistry). Since the key is the same, this overwrites the test version so that only the main version is stored. Since 5.2.2.Final used ArrayList, persistenceUnits.putAll added the test version and then the main version so that both were available for evaluation. Subsequently the test version was correctly identified and returned. |