hbm2ddl -- the problems and remedy

For a project I had to create ddl from the hibernate mapping files (hbm.xml). I started with following configuration. Remember you need not have database details of hibernate.cfg.xml file

hibernate.cfg.xml
<hibernate-configuration>
  <session-factory>
    <mapping resource="com/gvt/sch/hibernate/ApplicationEnvironment.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/UserRole.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/Application.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/TaskType.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/WorkStatus.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/Users.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/Roles.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/Contacts.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/EnvType.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/Discussions.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/WorkRegister.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/ErrorRepo.hbm.xml"/>
    <mapping resource="com/gvt/sch/hibernate/ErrorNature.hbm.xml"/>
  </session-factory>
</hibernate-configuration>



pom.xml
< project>
...............................................

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>3.0</version>
                <executions>
                    <execution>
                        <id>generate-ddl</id>
                        <goals>
                            <goal>hbm2ddl</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <hibernatetool>
                        <hbm2ddl create="true" export="false" outputfilename="create-ddl.sql" format="true" console="true">
                            <configuration configurationfile="src/main/resources/hibernate.cfg.xml"/>
                        </hbm2ddl>                     
                    </hibernatetool>
                </configuration>           
                <dependencies>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-entitymanager</artifactId>
                        <version>${org.hibernate.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>javassist</groupId>
                                <artifactId>javassist</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
            </plugin>

................................................
</project>


ERROR 
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.MappingNotFoundException: resource: com/gvt/sch/hibernate/ApplicationEnvironment.hbm.xml not found
[hibernatetool] A resource located at com/gvt/sch/hibernate/ApplicationEnvironment.hbm.xml was not found.
[hibernatetool] Check the following:
[hibernatetool]
[hibernatetool] 1) Is the spelling/casing correct ?
[hibernatetool] 2)      Is com/gvt/sch/hibernate/ApplicationEnvironment.hbm.xml available via the classpath ?
[hibernatetool] 3) Does it actually exist ?
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE 


 RESOLUTION
This is because we are trying to create ddl while compiling, and the mappings (hbm.xml) are not in classpath. Add them explicitly in the classpath, as below.

                <configuration>
                    <hibernatetool>
                        <hbm2ddl create="true" export="false" outputfilename="create-ddl.sql" format="true" console="true">
                            <configuration configurationfile="src/main/resources/hibernate.cfg.xml"/>
                        </hbm2ddl>
                        <classpath>
                            <pathelement location="C:\\Users\\xyz\\Documents\\NetBeansProjects\\search\\src\\main\\java"/>
                            <pathelement path="com/gvt/sch/hibernate/*.xml"/>
                            <pathelement path="com/gvt/sch/hibernate/*"/>
                        </classpath>                    
                    </hibernatetool>
                </configuration>

This will remove this particular error. Moving forward you may encounter few more errors.

 ERROR
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project search: There was an error creating the AntRun task. An Ant BuildException has occured: java.lang.NoClassDefFoundError: org/slf4j/helpers/NOPLoggerFactory: org.slf4j.helpers.NOPLoggerFactory -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project search: There was an error creating the AntRun task.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: There was an error creating the AntRun task.
        at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:84)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException has occured: java.lang.NoClassDefFoundError: org/slf4j/helpers/NOPLoggerFactory
        at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:283)
        at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:80)


 RESOLUTION 
Add the following dependencies in plugin dependencies, remember put them in plugin dependencies.
                      <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                        <version>1.7.10</version>
                    </dependency>
                    <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
                        <version>0.9.24</version>
                    </dependency>


 This will remove this particular error. Moving forward you may encounter few more errors.


ERROR 
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project search: There was an error creating the AntRun task. An Ant BuildException has occured: java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple; -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project search: There was an error creating the AntRun task.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: There was an error creating the AntRun task.
        at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:84)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException has occured: java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;  



 RESOLUTION 
Add the following dependencies in plugin dependencies, remember put them in plugin dependencies.
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                        <version>1.7.5</version>
                        <scope>compile</scope>
                    </dependency>


 This will remove this particular error. Moving forward I did not get any error, but beware of slf4j, it may give further troubles. 

 

Comments

Popular posts from this blog

Delete horizontal, vertical and angled lines from an image using Python to clear noise and read text with minimum errors

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

Java Currency Formatter Changing $ to ¤