6. Generate a mapping file from a datasheet
You can automatically generate the mapping file from the table in the database, download Middlegen-hibernate first, and then unzip it after downloading.
The database used here is MySQL, and assume that the following tables are already in your database:
CREATE TABLE user (
id INT(11) NOT NULL auto_increment PRIMARY KEY,
name VARCHAR(100) NOT NULL default '',
age INT
);
Into the Config/database directory after middlegen-hibernate decompression, open the Mysql.xml, modify the database configuration related information:
mysql.xml
<property name="database.script.file"
value="${src.dir}/sql/${name}-mysql.sql"/>
<property name="database.driver.file"
value="${lib.dir}/mysql-connector-java-3.0.14-production-bin.jar"/>
<property name="database.driver.classpath"
value="${database.driver.file}"/>
<property name="database.driver"
value="com.mysql.jdbc.Driver"/>
<property name="database.url"
value="jdbc:mysql://localhost/demo"/>
<property name="database.userid"
value="caterpillar"/>
<property name="database.password"
value="123456"/>
<property name="database.schema"
value=""/>
<property name="database.catalog"
value=""/>
<property name="jboss.datasource.mapping"
value="mySQL"/>
Configure according to the environment
database.driver.file
database.driver.classpath
database.driver
database.url
database.userid
database.password
, the default JDBC driver for MySQL is placed under the Middlegen-hibernate Lib directory.
Middlegen-hibernate use ant constructs, you can refer to ant introduction.