Use hbm2javatask to generateCodeIt is much easier to use than the schemaexport (configuration file to database) provided by hibernate.
I really don't know what the author did. It's so hard to write a schemaexport ......
1. Preparations before start
1.1 unzip hibernate-2.1.6.zip
1.2 hibernate-extensions-2.1.2.zip
1.3 export logging-log4j-1.2.9.zip
1.4 copy all related. Jar files to the lib directory under the project directory
1.5 know how to use ant. Read what I wroteArticle"Very simple ant file"
2. Create the project directory and file structure as follows:
Payment <dir> |-Src <dir> |-HBM <dir> |-Payment <dir> |-Payment. HBM. xml |-Classes <dir> |-Lib <dir> |-Build. xml |-Hibernate. codegen. xml |-Log4j. Properties |
3. Code of each file
3.1 Build. xml
<Project name = "" basedir = "./" default = "G"> <Path id = "p"> <Fileset dir = "lib/"> <Include name = "**/*. Jar"/> </Fileset> </Path><Target name = "G"> <Taskdef name = "G" classname = "net. SF. hibernate. tool. hbm2java. hbm2javatask" classpathref = "p"/> <G Config = "hibernate. codegen. xml" output = "src"> <Fileset dir = "HBM"> <Include name = "**/*. HBM. xml"/> </Fileset> </G> </Target> </Project> |
3.2 hibernate. codegen. xml
<? XML version = '1. 0' encoding = 'gbk'?> <Codegen> <Generate Renderer = "net. SF. hibernate. tool. hbm2java. basicrenderer"/> </Codegen> |
3.3 log4j. Properties
# Configure logging for testing Log4j. rootlogger = debug, stdout Log4j. appender. stdout = org. Apache. log4j. leleappender Log4j. appender. stdout. layout = org. Apache. log4j. simplelayout |
3.4 payment. HBM. xml
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> |
4. Note
In the 4.1 Build. xml file, the net. SF. hibernate. tool. hbm2java. hbm2javatask provided by the hibernate extensions package is defined as a task.
4.2 This task generates a. Java File Based on the hibernate configuration file ending with. HBM. XML in the HBM directory including the subdirectory and outputs it to the src directory. The output. Java path is based on the name attribute in the class label.
4.3 you must specify a class Renderer configuration file hibernate. codegen. XML for the hbm2javatask class.
4.3 check the output by configuring log4j. properties. Optional.