To generate a persisted object class (2.1.2) based on a configuration file using the Hibernate extension tool Hbm2java
Source: Internet
Author: User
Object
It is very easy to generate code using Hbm2java, which is much easier to use than the Schemaexport (profile to database) provided by Hibernate. I don't know what the author is doing, writing a schemaexport so hard ... 1. Before the beginning of the preparation 1.1 prepare Hibernate-2.1.6.zip 1.2 prepare Hibernate-extensions-2.1.2.zip 1.3 prepare Logging-log4j-1.2.9.zip 1.4 to put the relevant. jar Files all Duplicate The Lib directory under the engineering directory 1.5 knows how to use ant. Read my article "very simple Ant file" 2. Create the Engineering 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.properties3. Each file code 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 Testinglog4j.rootlogger=debug, stdoutlog4j.appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.layout=org.apache.log4j.simplelayout 3.4 Payment.hbm.xml<?xml version= "1.0" encoding= "GBK"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping dtd//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-2.0.dtd ">
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