休眠工具与 gradle,jdbc 错误



我正在尝试从 gradle 运行蚂蚁休眠工具,但收效甚微。 编译时出现以下错误:

[ant:hibernatetool] 运行导出器 #2:hbm2ddl 时发生异常(生成数据库架构) [蚂蚁:冬眠工具]要获取完整的堆栈跟踪,请使用 -verbose 运行 ant [ant:hibernatetool] org.hibernate.service.spi.ServiceException: 无法创建请求的服务 [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] [ant:hibernatetool] org.hibernate.exception.JDBCConnectionException: 调用 DriverManager#getConnection 时出错 java.sql.SQLException:没有找到适合 jdbc:mysql://localhost:3306 的驱动程序

我确定我正在将 mysql 连接器加载到类路径中(因为我已经打印出类路径以确认这一点)。

这是我尝试执行的代码。

configurations {
hibtools
}
dependencies {
hibtools "org.hibernate:hibernate-tools:5.2.3.Final"
hibtools "org.hibernate:hibernate-core:$hibernateVersion"
hibtools "org.hibernate:hibernate-c3p0:$hibernateVersion"
hibtools "org.hibernate.common:hibernate-commons-annotations:5.0.1.Final"
hibtools "org.hibernate:hibernate-entitymanager:$hibernateVersion"
hibtools group: 'org.dom4j', name: 'dom4j', version: '2.1.0'
hibtools group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
hibtools group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
hibtools 'mysql:mysql-connector-java:5.1.10'
hibtools group: 'org.springframework.security', name: 'spring-security-core', version: '4.1.5.RELEASE'
hibtools group: 'org.springframework', name: 'spring-tx', version: '4.1.5.RELEASE'
hibtools group: 'commons-codec', name: 'commons-codec', version: '1.11'
hibtools "log4j:log4j:1.2.17"
hibtools fileTree(dir: "${projectDir}/compsciBuild/lib", include: "**/*.jar")
hibtools fileTree(dir: "${projectDir}/lib", include: "**/*.jar")
}
task createdb(dependsOn: copy_c3p0){
doLast{
ant.taskdef(name: 'hibernatetool', classname: 'org.hibernate.tool.ant.HibernateToolTask', classpath: configurations.hibtools.asPath + classes_dir)
ant.hibernatetool(destdir: '${classes_dir}') {
ant.annotationconfiguration(configurationfile: "${classes_dir}/hibernate.cfg.xml")
ant.hbm2ddl(drop: 'true')
}
}
}

任何帮助将不胜感激

我也在官方 Gradle 论坛上发布了这个

休眠工具驱动程序问题

似乎在 hibernate 5 中,属性 connection.driver不适用于 gradle,必须更改为connection.driver_class。 一旦我在休眠.cfg.xml文件中更改了它,一切都按预期工作。

最新更新