DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • The 30 Seconds Before a Mobile App Crash: The Evidence Most Systems Never Capture
  • Wayland Compositor Debugging in C++: Hunting Null Pointer Crashes in the Display Stack
  • When AI Crashes: Classifying Failure Modes in Safety-Critical Software
  • Unhandled Promise Rejections: The Tiny Mistake That Crashed Our Node.js App

Trending

  • Evals in CI: How to Catch Agent Regressions Before Production Does
  • Giving AI Agents Safe Access to Legacy Systems: Introducing legacy2mcp
  • AI Agents for Software Engineering and Autonomous Development Workflows
  • Why AI Agents Need a Shared Enterprise Ontology

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Java
  4. Hibernate and JPA Tutorial: Crash Course [Video]

Hibernate and JPA Tutorial: Crash Course [Video]

Ever looked for a comprehensive tutorial to Hibernate and JPA that is fun and entertaining at the same time? Look no further than this video tutorial.

By 
Marco Behler
·
Aug. 26, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
7.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Ever looked for a comprehensive tutorial to Hibernate and JPA that is fun and entertaining at the same time?  The video tutorial below is a crash course into the Hibernate and JPA universe. From mapping annotations and SessionFactory setup to HQL and criteria queries, we cover all the basics you’ll need to get started with Hibernate and JPA. 

What’s in the Video?

There are so many terms when it comes to Hibernate: Hibernate (i.e., JPA, HQL, JPQL, and SQL) that we first have to understand what Hibernate is and what problem it tries to solve. The core problem is mapping between Java classes and relational database tables.

Afterward, we'll jump right into the project. You can choose to clone the sample project to follow along with this video, and we'll dive deeper into what dependencies you need to get started with Hibernate. Hint: It's not that many. In fact, it's only one: even though modern stacks like Spring Boot might make you believe differently.

Once we have the dependencies sorted out, we'll have a look at Hibernate's mapping annotations. One of the core ways to let Hibernate know about your database tables is through annotations such as @Entity, @Table, @Column, and many more. We'll play with those. We'll also figure out that one of the most popular Hibernate books spends roughly 200 pages on mapping annotations. A lot of work you have to go through yourself, which cannot be condensed into just a video.

Having the dependencies and annotations set up correctly means we can now go about creating a SessionFactory. A SessionFactory essentially is Hibernate. It's the core class you want to use whenever you want to, for example, fire queries against a database, or simply just save one of your objects.

When the SessionFactory is up and running, we can start considering how to make basic CUD queries work. We can create, update, and delete, but not yet send queries. Hence, we'll use the SessionFactory to do just that, save and update a couple of users we had previously created.

Let's add an "R" to CUD and make it fully CRUD by executing HQL queries against the database. HQL queries are Hibernate's way of querying database tables, though you don't write your HQL against specific database tables; rather, against your mapped object hierarchy. At the end of the day, Hibernate will transform the HQL into SQL for you and you'll see it printed out in the console.

Up next, let's solve the big question of what JPA, the Java Persistence API actually is. By just swapping out a couple of classes, we can actually turn our application from a Hibernate application into a JPA application. We'll also talk about the real-life implications this actually has.

Every project, sooner or later, wants to create dynamic SQL queries. Hibernate/JPA's way of doing that is through its Criteria API. It's a bit cumbersome to use, but it does the job. Again, it's several dozen pages in the official documentation, but we'll try our best and cover the core concepts of the Criteria API.

Before we come to a close, we'll also spend some time figuring out where Hibernate/JPA fits into the Spring Boot universe and how it compares to other projects, such as Spring Data JPA.

By the end of this video, you should have a good grasp of basic Hibernate and we'll finish by giving you some tips on what to learn next to become a Hibernate expert.

Enjoy.


Crash (computing) Hibernate

Opinions expressed by DZone contributors are their own.

Related

  • The 30 Seconds Before a Mobile App Crash: The Evidence Most Systems Never Capture
  • Wayland Compositor Debugging in C++: Hunting Null Pointer Crashes in the Display Stack
  • When AI Crashes: Classifying Failure Modes in Safety-Critical Software
  • Unhandled Promise Rejections: The Tiny Mistake That Crashed Our Node.js App

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook