I am creating a task for generating java classes from the database. I created a gradle task using ant. The strange this is that the task is expecting a hibernate.cfg.xml file for revengfile
property.
This is my gradle task:
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)
}
}
}
}
The revengfile
property overrides propertyfile
. I checked the documentation, there is an example with hibernate.reveng.xml
, but it actually only works with hibernate.cfg.xml
file.
This is my hibernate.cfg.xml
file:
<?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>
My hibernate.reveng.xml
file:
<?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>