1. First prepare the environment, the following Hibernate and its plug-in download address http://prdownloads.SourceForge.Net/Hibernate/?sort_by=date&sort=desc
Hibernate Middlegen-Hibernate Hibernate-Extions Ant http: //ant.apache.org jdbc for sqlserver2000
2.Hibernate basic code includes
Pojopojo should understand Domain Object.pojo corresponding to database tables in Hibernate is a normal Java object that "Plain Ordinary Java Object" is formatted. It can be understood as a value object that does not contain logic code (Value Object)
public class TUser implements Serializable {private String name; public User (String name) {this.name = name;} / ** default constructor * / public User () {} public String getName () {return this.name;} public Void setName (String name) {this.name = name;}} Hibernate mapping file Hibernate is an "object-relational data mapping" (OBJECT RELATIONALMAPPING) ORM. The front POJO is reflected here that the semantics of the Object layer in the ORM, and the mapping file is the link associated with the object (Object) with relational data, in Hibernate, mapping files usually ". HBM.XML "as a suffix.
3. By the database, the basic code Hibernate provides the Middle Gen for Hibernate and Hibernate_extension toolkit, which is easy to export the database table structure, generate ORM and POJO, based on existing databases. Here is an example.
4. Configure MiddleGen-Hibernate to C: / Work / MiddleGen.
5. Connect Hibernate to C: / Work / Hibernate.
6. Connectue EXTENTIONS to C: / WORK / EXTENTIONS
7. Enter the / config / database subdirectory of the MiddleGen directory. We use SQLServer2000 here, so choose MSSQL.xml
Open MSSQL.XML
Change here
After we install the downloaded JDBC for SQLServer2000, put the 3 JAR files below the installation directory / lib directory in the Lib Directory of MiddleGen.
// Database path. "JDBC.MICROFT.SQLSERVER"
Find keyword "! Entity", get: ]>
Because the default MiddleGen is HSQL.xml, modify our mssql.xml
]>
Modify the program's Name
changed to
Modify output directory lookup "name =" build.gen-src.dir "
Modified into
Modify Package Name Find " Modify the PACHAGE attribute to 9. Configure the path to the ANT, decompress the downloaded Ant, such as C: / Ant Let's right click on my computer -> familiar -> Advanced -> Edit Path Familiar Add C: / Ant / bin in the back 10. Click Start -> Run -> CMD CD to our middlegen directory, running Ant If prompted to connect the database failed, it is MSSQL.xml unconfigured If the connection database is successful, if you don't find Table, Schemas and Catalogs are not configured. 11. If there is no error, you will start an interface, then click on the top GENERAE to generate a Pojo file.