Getting Started 01 - Hibernate Required Category Library
Hibernate is an ORM solution that relies on the JDBC on the underlying operation of the database, so you must first get the JDBC driver, which we use mysql here, so you must first get the mysql JDBC driver: JDBC driver
Next, Hibernate is written in this article, Hibernate's last stability version is 2.1.6, and 3.0 is still in the test phase, which will be mainly 2.1.6, so you can get hibernate to the following URL- 2.1.6.zip:Hibernate official website
After unpacking hibernate-2.1.6.zip, Hibernate2.jar is necessary, and many JAR files are included in the lib directory, where DOM4J, CGLIB, Commons Collections, Commons logging, odmg4, and ehcache are necessary, The log4j is recommended, why use these JARs, in the Hibernate reference manual, you can open the reference manual in Doc / Reference, an English version and the Simplified Chinese version, the file format is available with HTML and PDF Both, the following lists are shown in Simplified Chinese:
DOM4J (required): Hibernate needs to use DOM4J when parsing XML configuration and XML image metad file.
CGLIB (required): Hibernate uses this code generation library enhancement class (in combination with Java reflex mechanism).
Commons Collections, Commit Logging (Required): Hibernate uses multiple tool class libraries that Apache Jakarta Commons project.
ODMG4 (required): Hibernate provides an optional ODMG compatible persistent management interface. If you need an image collection, you need this class library, even if you are not using the ODMG API.
EHCACHE (required): Hibernate can use different second-level Cache solutions. If you do not modify configuration, Ehcache provides the default Cache.
Log4j (optional): Hibernate uses the Commons Logging API, the latter can use the log4j as a mechanism for implementing the LOG of the underlying. If there is a log4j library in the upper and lower text catalogs, Commons logging uses log4j.properties files that log4j and it finds in the context class path. A Properties file containing an example in the Hibernate release package. So, if you want to see what happened behind the scene, copy the log4j.jar to your context class (it is in the src / directory).
The above is the JAR file listed in the Hibernate reference manual. Hibernate requires Java Transaction API, so you still need JTA.jar, so far, there is a total of ten JAR files:
MySQL-Connector-Java-3.0.14-Production-bin.jar
Jta.jar
Hibernate2.jar
CGLIB-FULL-2.0.2.jar
Commons-Collectes-2.1.1.jar
Commons-logging-1.0.4.jar
DOM4J-1.4.jar
Ehcache-0.9.jar
LOG4J-1.2.8.jarodmg-3.0.jar
Other JAR files will be set depending on your needs. For example, you should also use Ant, which is a quite help for automation constructing Hibernate, you can first check my other layout on Ant introduction: Ant Getting Started
Hibernate can run on a single machine or run in a web application. If it is running on a single machine, all used JAR files (including JDBC drivers) are set to ClassPath, if it is running on the web application In the program, the JAR file is placed in web-inf / lib, where the JDBC driver can also rely on JNDI to get a resource, set the way, or you can also first see this article about DBCP Introduction: DBCP introduction
After you are ready for these files, our next topic will introduce an example of a quick start.