如何让 hibernate3-maven-plugin hbm2ddl 找到 JDBC 驱动程序?
我有一个正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。您必须添加相应的 JDBC 驱动程序作为 PLUGIN 的依赖项。将其添加为模块的依赖项不会执行任何操作。这对我来说似乎很令人惊讶,实际上有点蹩脚。
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.