Book Image

Mastering Hibernate

By : Ramin Rad, Koushik Srinivas Kothagal
Book Image

Mastering Hibernate

By: Ramin Rad, Koushik Srinivas Kothagal

Overview of this book

Hibernate has been so successful since its inception that it even influenced the Java Enterprise Edition specification in that the Java Persistence API was dramatically changed to do it the Hibernate way. Hibernate is the tool that solves the complex problem of Object Relational Mapping. It can be used in both Java Enterprise applications as well as .Net applications. Additionally, it can be used for both SQL and NoSQL data stores. Some developers learn the basics of Hibernate and hit the ground quickly. But when demands go beyond the basics, they take a reactive approach instead of learning the fundamentals and core concepts. However, the secret to success for any good developer is knowing and understanding the tools at your disposal. It’s time to learn about your tool to use it better This book first explores the internals of Hibernate by discussing what occurs inside a Hibernate session and how Entities are managed. Then, we cover core topics such as mapping, querying, caching, and we demonstrate how to use a wide range of very useful annotations. Additionally, you will learn how to create event listeners or interceptors utilizing the improved architecture in the latest version of Hibernate.
Table of Contents (16 chapters)


In this chapter, we discussed Java's SPI and OSGi model. This was necessary in order to understand the event architecture. As we saw, event listeners can be registered as services to respond to certain actions that take place in the persistence context. This sophisticated architecture empowers Hibernate to be pluggable and enables runtime environments to act as service providers.

We also discussed interceptors, which offer capability similar to events, but they are easier to create and use. The simplicity of interceptors is due to their lacking the sophisticated architecture that is used by events. For this reason, they are less modular and pluggable.

Finally, we looked at envers, which enable entity versioning and audit mechanisms. We showed that it's simple to start tracking entity revisions. But browsing through the revisions requires a bit of coding. Luckily, Hibernate envers offers a rich API to make that easy as well.

Envers uses the same event architecture that we discussed,...