Configure MiddleGen and Extensions to generate HBM and Pojo with SQL Server.

xiaoxiao2021-04-04  238

Configure MiddleGen and Extensions to generate HBM and Pojo with SQL Server.

Author: Yang (http://blog.sina.com.cn/u/1237288325)

1. The software used and its version is as follows:

ANT-1.6.5

Middlegen-Hibernate-R5

Hibernate-extensions-2.1

Hibernate-2.1.6

Extraced above the D disk

2, configure ANT

Take Ant to D: root directory environment variable plus ant_home = d: // Ant

PATH = D: // Ant // bin; Enter an Ant in the DOS command, if the prompt appears, the ANT has been configured successfully:

BuildFile: build.xml does not exist! Build failed

3, configure MiddleGen-Hibernate:

3.1 Configuring the MSSQL.xml file, this file is used to configure the SQL Server database connection

Three JAR files (mssqlser.jar; msbase.jar; msutil.jar) copy to the Middle Gen-Hibernate-R5 / lib directory (mssqlser.jar; msbase.jar; msutil.jar) Copy.

There is a MSSQL.xml file in the MiddleGen-Hibernate-R5 / Config / Database directory, which is used to configure the connection of the SQL Server database. The content is modified as follows (red for the modification)

3.2 Configuring the Ant Operation File of MiddleGen-Hibernate-R5 Build.xml

]>

Point out the database configuration file used.

">

Points the path to the resulting * .hbm.xml output:

Configure hibernate:

Destination = "$ {build.gen-src.dir}"

Package = "org.hibernate.sample" ------ points out the position of the package where HBM is located.

GenxDoclettags = "true" ------ Indicates whether xdoclet tags are required in HBM.XML.

GenIntergratedCompositiveKeys = "false"

JavatypeMapper = "MiddleGen.plugins.hibAnate.HibernateJavatypemapper"

/>

Configure MiddleGen:

Appname = "$ {name}"

Prefsdir = "$ {src.dir}"

GUI = "$ {gui}"

DatabaseURL = "$ {database.URL}"

InitialContextFactory = "$ {java.naming.factory.initial}"

ProviderURL = "$ {java.naming.provider.URL}"

DataSourcejndiname = "$ {Datasource.jndi.Name}"

Driver = "$ {database.driver}"

UserName = "$ {database.userid}"

Password = "$ {database.password}"

Schema = "$ {database.schema}"

Catalog = "$ {database.catalog}" incrudeViews = "true" ------ pointing to include a view.

>

4, run MiddleGen-Hibernate:

Run Ant in the MiddleGen-Hibernate directory, enter the graphical interface of MiddleGen-Hibernate. You can set the characteristics of the table, and fields. Then press Genarate to generate an HBM.xml file.

5, configure hibernate-extensions

5.1 There are 3 tools in the Hibernate-Extensions / Tools / Bin directory, and their features are as follows:

5.1.1 Class2HBM.BAT

Generate mapping files according to Pojo Class

That is, based on the Java file written by your own table, generate the corresponding * .hbm.xml file;

5.1.2 DDL2HBM.BAT

Guide the library table structure by the database and generate a mapping file and Pojo. This function is overlapping with MiddleGen's function, nor is it mature enough (actually being discarded, no more maintenance);

5.1.3 hbm2java.bat

Generate the corresponding POJO according to the mapping file, ie, based on the * .hbm.xml file generated by MiddleGen, be regenerated into the corresponding * .java file

5.2 There is a setEnv.bat file in the hibernate-extensions-2.1.2 / tools / bin directory, changing its content:

Set jdbc_driver = d: /middlegen-hibernate-r5/lib/msqlser.jar

Set hibernate_home = .. / .. / hibernate-2.1.6

Set corelib =% hibernate_home% / lib

Set lib = .. / lib

Set props =% hibernate_Home% / SRC

SET CP =% JDBC_Driver%;% PROPS%;% hibernate_Home% / Hibernate2.jar;% CORELIB% / Commons-logging-1.0.4.jar;% Corelib% / Commons-Collections-2.1.1.jar;% CoreLib% /commons-lang-1.0.1.jar;%Corelib% / CGLIB-FULL-2.0.2.jar;%CoreLib% / Dom4j-1.4.jar;%CoreLib%/odmg-3.0.jar;%CoreLib%/XML -apis.jar;% Corelib% / Xerces-2.4.0.jar;% corelib% / xalan-2.4.0.jar;% lib% / jdom.jar;% lib% / .. / hibernate-tools.jar

6, run hibernate-extensions, generate POJO files according to HBM.XML

Run HBM2JAVA C: / Sample / ORG / Hibernate / Sample / *. XML --Output = C: / Sample /

About the Author: Yang, Master of Computer, Beijing Technology and Business University, worked in NEC-SI, Softbrain as java development work. Blog: http://blog.sina.com.cn/u/1237288325msn: South-Titan@hotmail.com

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

New Post(0)