- /** Overwrite values from propertie-file or set, if given */
- if (driverClassName != null)
- {
- if (properties.containsKey(DRIVER_CLASS))
- getLog().debug(
- "Overwriting property " +
- DRIVER_CLASS + "=" + properties.getProperty(DRIVER_CLASS) +
- " with the value " + driverClassName
- );
- else
- getLog().debug("Using the value " + driverClassName);
- properties.setProperty(DRIVER_CLASS, driverClassName);
- }
- if (url != null)
- {
- if (properties.containsKey(URL))
- getLog().debug(
- "Overwriting property " +
- URL + "=" + properties.getProperty(URL) +
- " with the value " + url
- );
- else
- getLog().debug("Using the value " + url);
- properties.setProperty(URL, url);
- }
- if (username != null)
- {
- if (properties.containsKey(USERNAME))
- getLog().debug(
- "Overwriting property " +
- USERNAME + "=" + properties.getProperty(USERNAME) +
- " with the value " + username
- );
- else
- getLog().debug("Using the value " + username);
- properties.setProperty(USERNAME, username);
- }
- if (password != null)
- {
- if (properties.containsKey(PASSWORD))
- getLog().debug(
- "Overwriting property " +
- PASSWORD + "=" + properties.getProperty(PASSWORD) +
- " with value " + password
- );
- else
- getLog().debug("Using value " + password + " for property " + PASSWORD);
- properties.setProperty(PASSWORD, password);
- }
- if (hibernateDialect != null)
- {
- if (properties.containsKey(DIALECT))
- getLog().debug(
- "Overwriting property " +
- DIALECT + "=" + properties.getProperty(DIALECT) +
- " with value " + hibernateDialect
- );
- else
- getLog().debug(
- "Using value " + hibernateDialect + " for property " + DIALECT
- );
- properties.setProperty(DIALECT, hibernateDialect);
- }
- if ( hibernateNamingStrategy != null )
- {
- if ( properties.contains(NAMING_STRATEGY))
- getLog().debug(
- "Overwriting property " +
- NAMING_STRATEGY + "=" + properties.getProperty(NAMING_STRATEGY) +
- " with value " + hibernateNamingStrategy
- );
- else
- getLog().debug(
- "Using value " + hibernateNamingStrategy + " for property " +
- NAMING_STRATEGY
+ /** Try to read configuration from configuration-file */
+ try
+ {
+ if (hibernateConfig == null)
+ {
+ URL url = classLoader.findResource("hibernate.cfg.xml");
+ if (url == null)
+ {
+ getLog().info("No hibernate.cfg.xml on the classpath!");
+ }
+ else
+ {
+ getLog().info("Reading settings from hibernate.cfg.xml on the classpath.");
+ config.configure(url);
+ }
+ }
+ else
+ {
+ File file = new File(hibernateConfig);
+ if (file.exists())
+ {
+ getLog().info("Reading configuration from file " + hibernateConfig + "...");
+ config.configure(file);
+ }
+ else
+ getLog().info("No hibernate-configuration-file found! (Checked path: " + hibernateConfig + ")");
+ }
+ }
+ catch (Exception e)
+ {
+ getLog().error("Error while reading configuration!", e);
+ throw new MojoExecutionException(e.getMessage());
+ }
+
+ ParsedPersistenceXmlDescriptor persistenceUnitDescriptor =
+ getPersistenceUnitDescriptor(
+ persistenceUnit,
+ config.getProperties(),
+ new MavenProjectClassLoaderService(classLoader)
+ );
+ if (persistenceUnitDescriptor != null)
+ config.setProperties(persistenceUnitDescriptor.getProperties());
+
+
+ /** Overwrite values from properties-file or set, if given */
+
+ if (driverClassName != null)
+ {
+ if (config.getProperties().containsKey(DRIVER_CLASS))
+ getLog().debug(
+ "Overwriting property " +
+ DRIVER_CLASS + "=" + config.getProperty(DRIVER_CLASS) +
+ " with the value " + driverClassName