如何获取hibernate3-maven-plugin hbm2ddl以查找JDBC驱动程序? [英] How to get hibernate3-maven-plugin hbm2ddl to find JDBC driver?

查看:133
本文介绍了如何获取hibernate3-maven-plugin hbm2ddl以查找JDBC驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Maven构建的Java项目.我现在正在尝试获取hibernate3-maven-plugin来运行hbm2ddl工具来生成schema.sql文件,我可以使用该文件从带注释的域类中创建数据库模式.这是一个使用Hibernate作为提供程序的JPA应用程序.

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.

在我的persistence.xml文件中,我调出mysql驱动程序:

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"/>

运行Maven时,我看到它正在处理我的所有类,但是当它输出模式时,会出现以下错误:

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

我将MySQL驱动程序作为此模块的依赖项.但是,似乎hbm2ddl工具无法找到它.我猜想Maven插件会在本地Maven文件存储库中搜索该驱动程序.有什么作用?

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?

我的pom.xml的相关部分是这样的:

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>

推荐答案

我知道了.您必须添加相应的JDBC驱动程序作为PLUGIN的依赖项.将其添加为模块的依赖项不会执行任何操作.这让我感到惊讶,实际上有点kind脚.

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>   

这篇关于如何获取hibernate3-maven-plugin hbm2ddl以查找JDBC驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆