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

Introduction


In this chapter, we will take a look at how the hibernate and ORM (Object-relational Mapping) frameworks work, how to configure hibernate in different ways, and the libraries that are required for the hibernate application. An essential part of the application is the hibernate configuration. Through the configuration, we can provide database information to the hibernate engine, such as the database host, port, username, password, the database name, the drive class, and so on.

In the older era of Java development, developers used some methodologies to persist data. To persist data means to save or store data in some storage medium by maintaining it in a certain state. Once the data is successfully persisted, it can be used at any given time. A database is the more preferable storage medium for a transactional operation. Usually, we use JDBC (Java Database Connectivity) to perform such operation with the database.

If we use the JDBC operation, we need to work a bit harder and take care of the following processes:

  • Opening a database connection

  • Maintaining an open connection

  • Building a query

  • Executing a query

  • Getting a response to the query

  • Mapping the query response with the custom classes

  • Closing the database connection

To avoid this hectic process, we can use the ORM tools available in the market. ORM stands for Object Relation Mapping. It works as a bridge between the application and database by simplifying the communication between them.

The benefits of the ORM framework are as follows:

  • It reduces the development time/cost.

  • It speeds up the development.

  • It provides us with portability. Hibernate supports multiple databases, so there is no need to write a database-specific code.

This is a useful feature of hibernate. Generally, all databases have their own syntax made up of Data Definition Language (DDL) or Data Manipulation Language (DML) statements. If we used JDBC, we would need to write a database-specific code as our database is changed. However, hibernate gets rid of the developer's headache by handling this issue.

The syntax of a query may be different for different database parameters; still, hibernate works in the same way for all types of databases. Hibernate's term dialect helps achieve this type of functionality. The implementation of the dialect class is provided by the database provider to inform hibernate about the syntax of this particular database.

Some useful features of hibernate are as follows:

  • Code reusability

  • Transaction management

  • Efficient collection/custom classes mapping

  • The caching mechanism supported by hibernate

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 €14.99/month. Cancel anytime}