Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Java Hibernate Cookbook

You're reading from  Java Hibernate Cookbook

Product type Book
Published in Sep 2015
Publisher
ISBN-13 9781784391904
Pages 250 pages
Edition 1st Edition
Languages

Table of Contents (15) Chapters

Java Hibernate Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Setting Up Hibernate 2. Understanding the Fundamentals 3. Basic Annotations 4. Working with Collections 5. Working with Associations 6. Querying 7. Advanced Concepts 8. Integration with Other Frameworks Index

Getting the required libraries for hibernate


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:

  • Manually downloading

  • Using Maven

Manually downloading

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.

How to do it…

Let's come back to the library section. Apart from JDBC, you will need the JAR files for hibernate. Perform the following steps:

  1. Download the hibernate core distribution from http://hibernate.org/orm/.

  2. Now, place all the files in your classpath if you plan to run a standalone program and put them in the lib folder if it's a J2EE project.

Note

When you manually download the libraries, it's the programmer's responsibility to get all the required and dependent JAR files from the official site of hibernate; failing this, they will face errors.

Using Maven

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.

How to do it…

  1. Enter the following code into the 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.

Note

Replace MySQL-connector-version with your required MySQL connector version in the <version>MySQL-connector-version</version> line, and replace hibernate-version with your required hibernate version in the <version>hibernate-version</version> line.

You have been reading a chapter from
Java Hibernate Cookbook
Published in: Sep 2015 Publisher: ISBN-13: 9781784391904
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime}