To work with hibernate, we need a JAR (Java Archive) file provided by hibernate. Here, we will see how to download the hibernate core distribution. There are multiple ways to get the required libraries; here, we will consider two of them:
The first and most basic JAR file needed is a JDBC driver. The JDBC driver is a bridge or an API between Java and the database. The JDBC driver provides us with the generic classes that will help us communicate with the database. Generally, the driver is either provided by the database provider or developed by communities; however, you have to get it yourself. This also depends on the type of the database you are using. As we will use the MySQL database for this book, we will use the Mysql-Connector.jar
file.
Let's come back to the library section. Apart from JDBC, you will need the JAR files for hibernate. Perform the following steps:
lib
folder if it's a J2EE project.If you use the Maven project, it would get rid of your headache of finding all the JAR files for hibernate and the dependent libraries. You can use the following Maven configuration for hibernate.
pom.xml
source file to show the dependency mapping of hibernate and MySQL in pom.xml
:… <dependencies> <!-- MySQL connector --> <dependency> <groupId>MySQL</groupId> <artifactId>MySQL-connector-Java</artifactId> <version>MySQL-connector-version</version> </dependency> <!-- Hibernate framework --> <dependency> <groupId>hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>hibernate-version</version> </dependency> <dependencies>
Using this method, Maven will download all the required JAR files related to hibernate and the dependent libraries required for hibernate.