Hibernate 简明教程
Hibernate - Environment Setup
本章解释如何安装 Hibernate 和其他相关软件包,为 Hibernate 应用程序准备环境。我们将使用 MySQL 数据库试验 Hibernate 示例,所以请确保已经为 MySQL 数据库设置了安装程序。有关 MySQL 的更多详细信息,您可以查看我们的 MySQL Tutorial 。
This chapter explains how to install Hibernate and other associated packages to prepare an environment for the Hibernate applications. We will work with MySQL database to experiment with Hibernate examples, so make sure you already have a setup for MySQL database. For more detail on MySQL, you can check our MySQL Tutorial.
Downloading Hibernate
假设您已经在系统上安装了最新版本的 Java。以下是下载和安装 Hibernate 到系统中的简单步骤:
It is assumed that you already have the latest version of Java installed on your system. Following are the simple steps to download and install Hibernate on your system −
-
Make a choice whether you want to install Hibernate on Windows, or Unix and then proceed to the next step to download .zip file for windows and .tz file for Unix.
-
Download the latest version of Hibernate from http://www.hibernate.org/downloads.
-
At the time of writing this tutorial, I downloaded hibernate-distribution 5.3.1.Final from mvnrepository and when you unzip the downloaded file, it will give you directory structure as shown in the following image
Installing Hibernate
下载并解压缩最新版本的 Hibernate 安装文件后,您需要执行以下两个简单步骤。确保正确设置 CLASSPATH 变量,否则在编译应用程序时将会遇到问题。
Once you downloaded and unzipped the latest version of the Hibernate Installation file, you need to perform following two simple steps. Make sure you are setting your CLASSPATH variable properly otherwise you will face problem while compiling your application.
-
Now, copy all the library files from /lib into your CLASSPATH, and change your classpath variable to include all the JARs −
-
Finally, copy hibernate3.jar file into your CLASSPATH. This file lies in the root directory of the installation and is the primary JAR that Hibernate needs to do its work.
Hibernate Prerequisites
以下是 Hibernate 所需的软件包/库列表,在使用 Hibernate 之前应安装这些软件包/库。要安装这些软件包,您需要将 /lib 中的库文件复制到 CLASSPATH 中,并相应地更改 CLASSPATH 变量。
Following is the list of packages/libraries required by Hibernate and you should install them before starting with Hibernate. To install these packages, you will have to copy library files from /lib into your CLASSPATH, and change your CLASSPATH variable accordingly.
Sr.No. |
Packages/Libraries |
1 |
MySQL Connector/J MySQL Driver https://dev.mysql.com/downloads/connector/j/ |
2 |
Java EE Java EE API J2EE API |
Hibernate Nice to have Prerequisites
以下是 Hibernate 所需的可选软件包/库列表,您可以安装它们来启用 Hibernate。要安装这些软件包,您需要将 /lib 中的库文件复制到 CLASSPATH 中,并相应地更改 CLASSPATH 变量。
Following is the list of optional packages/libraries required by Hibernate and you can install them to starting with Hibernate. To install these packages, you will have to copy library files from /lib into your CLASSPATH, and change your CLASSPATH variable accordingly.
Sr.No. |
Packages/Libraries |
1 |
dom4j XML parsing www.dom4j.org/ |
2 |
Xalan XSLT Processor https://xml.apache.org/xalan-j/ |
3 |
Xerces The Xerces Java Parser https://xml.apache.org/xerces-j/ |
4 |
cglib Appropriate changes to Java classes at runtime http://cglib.sourceforge.net/ |
5 |
log4j Logging Faremwork https://logging.apache.org/log4j |
6 |
Commons Logging, Email etc. https://jakarta.apache.org/commons |
7 |
SLF4J Logging Facade for Java https://www.slf4j.org |