Use the Hibernate extension tool HBM2JAVASK to generate a persistent object class according to the configuration file (2.1.2)

xiaoxiao2021-03-05  29

It is very easy to use HBM2javaTask to generate code, which is much easier than the use of SchemaExport (profile to database) provided by Hibernate. I really don't know how the author is engaged, I'm writing SchemaExport is so difficult ... 1. Prepare before the beginning 1.1 Prepare hibernate-2.1.6.zip 1.2 Prepare Hibernate-extensions-2.1.2.zip 1.3 Preparation Logging -log4j-1.2.9.zip 1.4 Related .jar files All copied to the lib directory 1.5 know how to use Ant. I can read the article "very simple ANT file" 2. Create an engineering directory and the file structure.

Payment

| -hbm | -payment | -payment.hbm.xml | -classes | -lib | -build.xml | -hibernate. Codegen.xml | -log4j.properties

3. Each file code

3.1 Build.xml

< / fileset>

3.2 Hibernate.codegen.xml

3.3 log4j.properties

# Configure logging for testinglog4j.rootlogger = debug, stdoutLog4j.appender.stdout = org.apache.log4j.consolerappenderlog4j.Appender.stdout.Layout = Org.apache.log4j.simpleLayout

3.4 payment.hbm.xml

4. Description

4.1 Build.xml files Net.sf.hibernate.tool.hbm2java.hbm2javatask provided by the Hibernate Extensions package is defined as a task.

4.2 This task generates .java files according to all Hibernate configuration files ending in subdirectory according to the HBM directory, and output to the src directory. Output. Java path is based on the Name property in the Class tag.

4.3 Need to specify a class renderer profile hibernate.codegen.xml to the HBM2Javatask class.

4.3 Configuring Log4j.properties View Output, Optional.

转载请注明原文地址:https://www.9cbs.com/read-38580.html

New Post(0)