views:

506

answers:

1

I have a Java project I am building with Maven. I am now trying to get the hibernate3-maven-plugin to run the hbm2ddl tool to generate a schema.sql file I can use to create the database schema from my annotated domain classes. This is a JPA application that uses Hibernate as the provider.

In my persistence.xml file I call out the mysql driver:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

When I run Maven, I see it processing all my classes, but when it goes to output the schema, I get the following error:

ERROR org.hibernate.connection.DriverManagerConnectionProvider - JDBC Driver class not found: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

I have the MySQL driver as a dependency of this module. However it seems like the hbm2ddl tool cannot find it. I would have guessed that the Maven plugin would have known to search the local Maven file repository for this driver. What gives?

The relevant part of my pom.xml is this:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>hibernate3-maven-plugin</artifactId>
   <executions>
      <execution>
         <phase>process-classes</phase>
         <goals>
            <goal>hbm2ddl</goal>
          </goals>
      </execution>
   </executions>
   <configuration>
       <components>
          <component>
             <name>hbm2ddl</name>
             <implementation>jpaconfiguration</implementation>
          </component>
        </components>
        <componentProperties>
            <persistenceunit>my-unit</persistenceunit>
        </componentProperties>
   </configuration>       
</plugin>
A: 

I figured it out. You have to add the corresponding JDBC driver as a dependency of the PLUGIN. Adding it as a dependency of the module does nothing. This seems surprising to me and kind of lame actually.

    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <type>jar</type>
            <version>5.0.8</version>
        </dependency>
    </dependencies>   
HDave
A plugin class path is isolated from the project class path and that's not lame at all. It would be **very** annoying if it wasn't ("no, you can't use this dependency in your project because it brakes this plugin"). So it makes sense to have to declare them inside the plugin.
Pascal Thivent
You are correct, of course. Just venting after 4 lost hours of work.
HDave