Я создаю задачу для создания классов Java из базы данных.Я создал задачу Gradle, используя муравья.Странно то, что задача ожидает файл hibernate.cfg.xml для свойства revengfile
.
Это мое задание:
task hibernate{
description "Generates Java Classes from the Database Schema."
group "Hibernate"
doLast{
ant {
def base = "$projectDir/src/main/java"
taskdef(name: 'hibernatetool',
classname: 'org.hibernate.tool.ant.HibernateToolTask',
classpath: configurations.compile.asPath )
hibernatetool( destdir : "$base" ) {
jdbcconfiguration(
propertyfile:"src/main/resources/hibernate.properties", revengfile:"src/main/resources/hibernate.reveng.xml", //expects hibernate.cfg.xml instead
packagename: springProperties["hibernate.generate.package"], detectmanytomany:"true" )
hbm2java(ejb3:true)
}
}
}
}
Свойство revengfile
переопределяет propertyfile
.Я проверил документацию , есть пример с hibernate.reveng.xml
, но на самом деле он работает только с файлом hibernate.cfg.xml
.
Это мой hibernate.cfg.xml
файл:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://0.0.0.0:3308/db</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">pw</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.connection.zeroDateTimeBehavior">convertToNull</property>
</session-factory>
</hibernate-configuration>
Мой hibernate.reveng.xml
файл:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
SYSTEM "http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog=".*" match-schema=".*" match-table=".*" />
<table schema="db" name="string" class="StringEntity"></table>
</hibernate-reverse-engineering>