Create a Hibernate database table mapping file using Middlegen

Source: Internet
Author: User
Tags config modify mysql
Data | Database 1: Download MIDDLEGEN-HIBERNATE-R5
Address: URL Http://voxel.dl.sourceforge.net/sourceforge/hibernate/Middlegen-Hibernate-r5.zip
2: Decompression
Unzip the download, such as D:\Middlegen-Hibernate-r5
3: Config database file
Enter the D:\MIDDLEGEN-HIBERNATE-R5 directory under the \config\database subdirectory, select the database file you want, I use MySQL.
will be the original
<property name= "Database.driver.file" value= "${lib.dir}/mysql-connector-java-3.0.0-beta-bin.jar"/>
Change into
<property name= "Database.driver.file" value= "${lib.dir}/mysql-connector-java-3.0.15-ga-bin.jar"/>
Specify both the database and the user name. My configuration is as follows (the red part is the part to be modified)
<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.0-beta-bin.jar"/-->
<property name= "Database.driver.file" value= "${lib.dir}/mysql-connector-java-3.0.15-ga-bin.jar"/>
<property name= "Database.driver.classpath" value= "${database.driver.file}"/>
<property name= "Database.driver" value= "Org.gjt.mm.mysql.Driver"/>
<property name= "Database.url" value= "Jdbc:mysql://localhost/hibernate"/>
<property name= "Database.userid" value= "root"/>
<property name= "Database.password" value= ""/>
<property name= "Database.schema" value= ""/>
<property name= "Database.catalog" value= ""/>
<property name= "jboss.datasource.mapping" value= "MySQL"/>

Mysql-connector-java-3.0.15-ga-bin.jar copy of MySQL driver to D:\Middlegen-Hibernate-r5\lib

4: Modify the Build.xml
Modify the Build.xml file in the D:\MIDDLEGEN-HIBERNATE-R5 directory, this file is Middlegen-hibernate ant
Build the configuration. Middlegen-hibernate will generate database table mappings based on specific parameters in the Build.xml file
File

1) Row 24th Modify database connection
Change the hsqldb.xml into Mysql.xml
<! ENTITY database SYSTEM "File:./config/database/mysql.xml" >
2) Line 52nd Modify output directory
Change the ${BUILD.DIR}/GEN-SRC to the directory you want.
<property name= "Build.gen-src.dir" value= "D:/middlegen-hibernate-r5/sample"/>
3) line 184th of the corresponding code package name
The default setting for the Hibernate node package property is actually the previous
Application Name (${name}) and ". Hibernate" combined, depending on our needs,
Change it to
destination= "${build.gen-src.dir}"
Package= "Org.hibernate.sample"
Genxdoclettags= "true"
Genintergratedcompositekeys= "false"
Javatypemapper= "Middlegen.plugins.hibernate.HibernateJavaTypeMapper"
/>
There is also a property genxdoclettags, and if set to true, the generated code will contain
Xdoclet tag.
4) Line 33rd modify the application name
will be the original
<property name= "name" value= "Airline"/>
Change into
<property name= "name" value= "Hibernatesample"/>

5: Switch to D:\MIDDLEGEN-HIBERNATE-R5 directory, run Ant
The interface is as follows



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.