prerequisites:
Ant and mysql databases have been installed, and the database table has been established.
1. Download MiddleGen-Hibernate and Hibernate-Extensions from the official website of Hibernate and decompressed.
2, configure MiddleGen-Hibernate:
2. Configuring a database connection
Assuming the connection database is MySQL, there is a mysql.xml file in the MiddleGen-Hibernate-R5 / Config / Database directory, which is used to configure the connection of the MySQL database. The content is:
Copy MySQL-Connector-Java-3.0.15-Ga-bin.jar to $ {lib.dir}, which is the MiddleGen-Hibernate-R5 / Lib directory.
Modify the database connection items in the configuration file Database.URL, Database.Userid, Database.Userid enables MiddleGen-Hibernate to find the database.
2.2 Configuring the ANT Run File of MiddleGen-Hibernate-R5 Build.xml
]>
Point out the database configuration file used.
Point out your app name.
Indicates the output path of the HBM.
Destination = "$ {build.gen-src.dir}" Package = "org.hibernate.sample" GenxDoclettags = "false" GenIntergratedCompositiveKeys = "false" JavatypeMapper = "MiddleGen.plugins.hibAnate.HibernateJavatypemapper" /> It is pointed out the position of the package where HBM is located. It is pointed out whether xdoclet tags are required in HBM.XML. 3, run MiddleGen-Hibernate: Run Ant in the MiddleGen-Hibernate directory, enter the graphical interface of MiddleGen-Hibernate. You can set the characteristics of the table, and fields. Then press Genarate to generate an HBM.xml file. 4, configure hibernate-extensions There is a setEnv.bat file in the hibernate-extensions-2.1.2 / tools / bin directory, changing its contents: Set jdbc_driver = c: /java/middlegen-hibernate-r5/lib/mysql-connector-java-3.0.15-ga-bin.jar Set hibernate_home = c: /java/hibernate-2.1.6 Set corelib =% hibernate_home% / lib Set lib = .. / lib Set props =% hibernate_Home% / SRC SET CP =% JDBC_Driver%;% PROPS%;% hibernate_Home% / Hibernate2.jar;% CORELIB% / Commons-logging-1.0.4.jar;% Corelib% / Commons-Collections-2.1.1.jar;% CoreLib% /commons-lang-1.0.1.jar;%Corelib% / CGLIB-FULL-2.0.2.jar;%CoreLib% / Dom4j-1.4.jar;%CoreLib%/odmg-3.0.jar;%CoreLib%/XML -apis.jar;% Corelib% / Xerces-2.4.0.jar;% corelib% / xalan-2.4.0.jar;% lib% / jdom.jar;% lib% / .. / hibernate-tools.jar Note that the red font prompt is the path and JAR file name, must be correct. 5, run hibernate-extensions, generate POJO files according to HBM.XML Run HBM2JAVA C: / Sample / ORG / Hibernate / Sample / *. XML --Output = C: / Sample /