1. In the open source website http://prdownloads.sourceforge.net/Hibernate/ Download the three compressed packs (Hibernate, Middle Gen, Hibernate-Extensions-2.1.3), separately decompressed.
2. Configure the parameters of the corresponding database XML file in the config / database / directory in the MiddleGen directory.
3. Find the build.xml file in the root of MiddleGen
]>
Segment, modify "Oracle.xml" to the corresponding database configuration file, and modify the parameters such as the package name, path, project name of the generated code.
4. In command line mode, switch to MiddleGen's root directory, execute Ant, will start MiddleGen interface, MiddleGen's detailed settings, please refer to the corresponding document, then click the button to generate, MiddleGen will specify in the build file. The path generates the mapping file for hibernate.
5. Switch to the "/ Tools / Bin" directory of the Hibernate-Extensions-2.1.3 directory, modify the jdbc_driver, hibernate_home, hibernatetools_home segment in the file "setnv.bat", and check the package name in the CP segment, follow the unit Configuration detailed check, some package names are there without version number, but the default configuration file contains version numbers and should be removed. The results after I configure are as follows:
@echo off
Rem ------------------------------------- ---------------- Rem Setup Environment for Hibernate ToolsRem -------------------------- -----------------------------------------
Set jdbc_driver = c: /downloads/middlegen/lib/classes12.jarset Hibernate_Home = C: /Downloads/Hibernate-2.1
Set hibernateTools_Home = C: /Downloads - 2.1.3/toolsecho hibernatetools_home set to% hibernatetools_home%
if "% HIBERNATE_HOME%" == "" goto noHIBERNATEHomeset CORELIB =% HIBERNATE_HOME% / libset LIB =% HIBERNATETOOLS_HOME% / libset CP =% CLASSPATH%;% JDBC_DRIVER%;% HIBERNATE_HOME% / hibernate2.jar;% CORELIB% / commons- Logging.jar;% corelib% / commons-lang.jar;% corelib% / cglib2.jar;% corelib% / dom4j.jar;% corelib% / odmg.jar;% Corelib% / XML-Apis.jar;% CoreLib % / Xerces.jar;% Corelib% / Xalan.jar;% lib% / jdom.jar;% corelib% / commons-collections.jar;% lib% / .. / hibernate-Tools.jar
if not "% hibernate_Home%" == "" goto end
: NohibernateHomeecho Hibernate_Home Is Not Set. Please set hibernate_home.goto end
: END: END
6. Execute in the "/ Tools / Bin" directory of the hibernate-extensions-2.1.3 directory
HBM2JAVA "HBM file path plus file name, can be the path of Java file" - "--output ="
Such as: HBM2JAVA C: / Simple / *. XML --Output = C: / Simple will generate a corresponding POJO in the "C: / Simple directory".
This is done by the work of generating the Hibernate underlying code via MiddleGen.