-- Hibernate application configuration -- middlegen
************************************
Ant Configuration
************************************
Download ant and decompress it.
Test ant in C: And directory
Add ant_home = C: // ant to the environment variable.
Path = C: // ant // bin;
Enter the command line mode and enter: ant
For example:
C: //> ant
Buildfile: Build. XML does not exist!
Build failed
This prompt is displayed, indicating that ant has been configured successfully.
************************************
Middlegen hibernate Configuration
************************************
Is the O/R Mapping Tool of hibernate.
Http://hibernate.bluemars.net/98.html
*. HBM. xml file can be generated, which is a ing file required by hibernate.
Download middlegen hibernate, unzip, such as D: // Hiber // Middlegen-Hibernate-r1 //
Go to the directory,
[Configuration database, take Ms sqlserver as an example, JDBC driver for jsql connect (www.j-netdirect.com )]
1. Enter the/config/database/directory.
2. Test the jsqlconnect. Jar driver to the/lib/directory.
3. Edit the MSSQL. xml file as follows:
<Property name = "database. Script. File" value = ""/>
<Property name = "database. Driver. File" value = "$ {Lib. dir}/jsqlconnect. Jar"/>
<Property name = "database. Driver" value = "com. jnetdirect. jsql. jsqldriver"/>
<Property name = "database. url" value = "JDBC: jsqlconnect: // database server name or IP/database = Name of the database to be operated"/>
<Property name = "database. userid" value = "database username"/>
<Property name = "database. Password" value = "Database Password"/>
<Property name = "database. schema" value = ""/>
<Property name = "database. catalog" value = ""/>
<Property name = "JBoss. datasource. Mapping" value = "Ms sqlserver2000"/>
[Edit middlegen hibernate configuration]
1. Edit build. xml
2. Modify the default database file. Find this line, which is about 22 lines.
<! Doctype project [
<! -- Entity Database System "file:./config/database/HSQLDB. xml" --> // comment out the original content
<! Entity Database System "file:./config/database/MSSQL. xml"> // Add
]>
3. Edit the output root directory name and find the row, which is about 30 rows.
<! -- Property name = "name" value = "Airline"/--> // original content, comment out
<Property name = "name" value = "com"/> // Add the value you want, such as com
4. Edit the output package name and find the row, which is about 210 lines.
<! -- Hibernate
Destination = "$ {build. gen-src.dir }"
Package = "$ {name}. hibernate"
/--> // Comment out the original content
<Hibernate
Destination = "$ {build. gen-src.dir }"
Package = "$ {name}. test"
//> // Add, the generated XML file uses com. Test as your package.
The output directory is/build/Gen-src/COM/test/*. HBM. XML (* for the corresponding table, name it your own defined name)
5. Define the output directory, locate the row, and at the end of the document
<Target name = "Validate">
<Xmlvalidate failonerror = "no" lenient = "no" Warn = "yes">
<Fileset dir = "$ {build. gen-src.dir}/COM/test "supported des = "*. XML "/> to the directory structure you want to output. It is best to use the structure of your package as the directory structure.
</Xmlvalidate>
</Target>
6. When connecting to SQL Server, the system prompts that the database connection is successful, but no table exists. Find this row.
<Middlegen
Appname = "$ {name }"
Prefsdir = "$ {SRC. dir }"
Gui = "$ {GUI }"
Databaseurl = "$ {database. url }"
Initialcontextfactory = "$ {java. Naming. Factory. Initial }"
Providerurl = "$ {java. Naming. provider. url }"
Performancejndiname = "$ {datasource. JNDI. name }"
Driver = "$ {database. Driver }"
Username = "$ {database. userid }"
Password = "$ {database. Password }"
Schema = "$ {database. schema}" // remove
Catalog = "$ {database. Catalog}" // you can remove it.
>
[Completed]
After the configuration is complete, run ant in the root directory
A visual operation interface appears,
By default, the corresponding name is generated based on the table name and field name. You can also define the name by yourself. If the corresponding name is correct, click Generate.
/Build/gen-src/com/test/*. hbm. xml, the corresponding XML file is generated.
************************************
Hibernate-extensions-2.0 application configuration
************************************
This is a hibernate tool. There are 3 tools in/tools.
Class2hbm. bat generates the *. hbm. xml file based on the java file written in the corresponding table.
Ddl2hbm. bat automatically generates * based on your database table *. hbm. xml and *. java file (if you do not need detailed configuration, we recommend using this method to generate *. xml and *. java files)
Hbm2java. bat generates the *. java file according to *. hbm. xml.
Compile with ant before using it.
[Note]
Build. xml
<Property name = "hibernate-core.home" value = ".../hibernate-2.0"/> // find this row, about 40
Value: Decompress the hibernate directory.
[Compiled]
The compiled files are stored in/tools/target/hibernate-tools-2.0/
Now you can use the compiled execution file for ing and conversion.
[Application]
Hbm2java. bat
1. Enter the command line mode, enter the hibernate-tools-2.0 directory, and enter/bin
2. First Run setenv. BAT and set the environment variables. Before running, check the setenv. BAT file and open it in a text editor. Find the following lines:
Set jdbc_driver = C: // progra ~ 1 // sqllib // Java // db2java.zip; C: // mm. mysql-2.0.14 // mm. mysql-2.0.14-bin.jar; D: // j2sdk1.4.1 // lib // jsqlconnect. Jar
// Add your JDBC driver
Rem set hibernate_home =... // .. // hibernate-2.0 // The original
Set hibernate_home = D: // Hiber // hibernate-2.0 // change it to the directory where your current hibernate-2.0 is located
3. Execute hbm2java. bat D: // Hiber // com // test //*. XML // what follows is what you generated using middlegen hibernate *. HBM. XML file
Ddl2hbm. bat
Steps 1 and 2, such as hbm2java
3. Run ddl2hbm. A graphic interface is displayed.
4. On the connection panel, enter information about the JDBC driver, for example:
Driverclass: COM. jnetdirect. jsql. jsqldriver
Connectionurl: JDBC: jsqlconnect: // server name/database = Database Name & User = User Name & Password = Password)
UserName: User Name (My ConnectionUrl has filled in this information, which is optional here)
PassWord: PassWord (My ConnectionUrl has filled in this information, which is optional here)
5. On the Code panel, you can define the package name.
6. On the Output panel, you can define the file Output path.
7. After setting, go to the Table panel and click tables... Button. If the database connection is successful, a small panel will pop up, select the database you want to map, and click OK.
The Table panel displays all the tables of the database. Select the expected Table and click "Generate" to Generate the *. hbm. xml and *. java files in the output path.
[Note]
Because Sqlserver does not support the sequences type in hibernate, an error occurs during code testing. You can open the generated *. hbm. xml
Set
<Id column = "test_id" name = "id" type = "java. lang. Long">
<Generator class = "identity"/> // change it to identity.
</Id>