How to get hibernate3-maven-plugin hbm2ddl to find JDBC driver?

你说的曾经没有我的故事 提交于 2019-12-06 12:45:17

问题


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>

回答1:


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>   


来源:https://stackoverflow.com/questions/2831474/how-to-get-hibernate3-maven-plugin-hbm2ddl-to-find-jdbc-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!