如何让 hibernate3-maven-plugin hbm2ddl 找到 JDBC 驱动程序?

发布于 2024-09-01 15:56:53 字数 1614 浏览 8 评论 0原文

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

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

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

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

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 文件存储库中搜索该驱动程序。什么给?

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

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初相遇 2024-09-08 15:56:53

我想通了。您必须添加相应的 JDBC 驱动程序作为 PLUGIN 的依赖项。将其添加为模块的依赖项不会执行任何操作。这对我来说似乎很令人惊讶,实际上有点蹩脚。

    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <type>jar</type>
            <version>5.0.8</version>
        </dependency>
    </dependencies>   

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>   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文