Use the hibernate extension tool hbm2javatask to generate a Persistent Object Class Based on the configuration file (2.1.2)

Source: Internet
Author: User

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.

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.