2 Starting a project


This chapter covers

  • Overviewing the Hibernate and Spring Data projects
  • Developing a “Hello World” with Jakarta Persistence API, Hibernate, and Spring Data
  • Examining the configuration and integration options

In this chapter, we’ll start with Jakarta Persistence API (JPA), Hibernate, and Spring Data using a step-by-step example. We’ll see the persistence APIs and how to benefit from using either standardized JPA, native Hibernate, or Spring Data. We first offer a tour through JPA, Hibernate, and Spring Data with a straightforward “Hello World” application. We remind that JPA (Jakarta Persistence API, formerly Java Persistence API), is the specification defining an API that takes care of managing the persistence of objects and object-relational mappings – it will tell what to do to persist objects. Hibernate, the most popular implementation of this specification, will tell how to effectively make the persistence. Spring Data makes the implementation of the persistence layer even more efficient and is an umbrella project that adheres to the Spring framework principles and comes with an even simpler approach.

2.1 Introducing Hibernate

Object-relational mapping (ORM) is a programming technique making the connection between the incompatible worlds of object-oriented systems and relational databases.

2.2 Introducing Spring Data

2.3 “Hello World” with JPA

2.3.1 Configuring a persistence unit

2.3.2 Writing a persistent class

2.3.3 Storing and loading messages

2.4 Native Hibernate configuration

2.5 Switching between JPA and Hibernate

2.6 “Hello World” with Spring Data JPA

2.7 Comparing the approaches of persisting entities

2.8 Summary