From 5504979ec926b927755a3e4bfd93a406bb4d07b9 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 2 Jun 2017 10:38:32 +0200 Subject: [PATCH] Upgraded Hibernate * hibernate-core 5.2.4.Final -> 5.2.10.Final * hibernate-validator 5.3.1.Final -> 5.4.1.Final --- pom.xml | 4 +- .../plugins/hibernate/AbstractSchemaMojo.java | 45 +++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index a6521478..c69da308 100644 --- a/pom.xml +++ b/pom.xml @@ -131,8 +131,8 @@ UTF-8 - 5.2.4.Final - 5.3.1.Final + 5.2.10.Final + 5.4.1.Final 3.0.0 3.3.3 1.0.1 diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java index 0f143f59..edf8d125 100644 --- a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java @@ -490,8 +490,7 @@ public abstract class AbstractSchemaMojo extends AbstractMojo LoadedConfig config = loadConfig(configLoader); if (config != null) properties.putAll(config.getConfigurationValues()); - ParsedPersistenceXmlDescriptor unit = - loadPersistenceUnit(classLoaderService, properties); + ParsedPersistenceXmlDescriptor unit = loadPersistenceUnit(properties); if (unit != null) properties.putAll(unit.getProperties()); @@ -1346,53 +1345,51 @@ public abstract class AbstractSchemaMojo extends AbstractMojo } private ParsedPersistenceXmlDescriptor loadPersistenceUnit( - ClassLoaderService classLoaderService, Properties properties ) throws MojoFailureException { - PersistenceXmlParser parser = - new PersistenceXmlParser( - classLoaderService, - PersistenceUnitTransactionType.RESOURCE_LOCAL - ); - - Map units = - parser.doResolve(properties); + List units = + PersistenceXmlParser.locatePersistenceUnits(properties); if (persistenceUnit == null) { - Iterator names = units.keySet().iterator(); - if (!names.hasNext()) + if (units.isEmpty()) { getLog().info("Found no META-INF/persistence.xml."); return null; } - String name = names.next(); - if (!names.hasNext()) + if (units.size() == 1) { - getLog().info("Using persistence-unit " + name); - return units.get(name); + ParsedPersistenceXmlDescriptor descriptor = units.get(0); + getLog().info("Using persistence-unit " + descriptor.getName()); + return descriptor; } StringBuilder builder = new StringBuilder(); builder.append("No name provided and multiple persistence units found: "); - builder.append(name); - while(names.hasNext()) + Iterator it = units.iterator(); + while(it.hasNext()) { - builder.append(", "); - builder.append(names.next()); + builder.append(it.next().getName()); + if (it.hasNext()) + builder.append(", "); } builder.append('.'); throw new MojoFailureException(builder.toString()); } - if (units.containsKey(persistenceUnit)) + Iterator it = units.iterator(); + while(it.hasNext()) { - getLog().info("Using configured persistence-unit " + persistenceUnit); - return units.get(persistenceUnit); + ParsedPersistenceXmlDescriptor descriptor = it.next(); + if (descriptor.getName().equals(persistenceUnit)) + { + getLog().info("Using configured persistence-unit " + persistenceUnit); + return descriptor; + } } throw new MojoFailureException("Could not find persistence-unit " + persistenceUnit); -- 2.20.1