Getting started with Hibernate and JPA (Java Persistence API) can be tricky, but this step-by-step tutorial explains exactly what needs to be done to set up your application to use this technology. This chapter covers very basic mapping and persistence.
When we are finished with this tutorial, we will have a standalone Java SE application with database connectivity. This article is part of a series: Guide to Hibernate Annotations
So Java EE 6 is out, and you’ve decided to give it a go. You’re trying to port an existing application over to the new stack (or are trying to create a new one for the first time,) but exceptions are bursting through the seams and you just can’t seem to get things to work. If you’re familiar with Spring and Hibernate (with all the joy that is OpenSessionInView or
OpenSessionInConversation,) more than likely the problems you’re having are related to the Java Persistence API (
JPA), combined with Enterprise Java Beans (
EJB). Contexts and Dependency Injection (
CDI) should be a familiar face if coming from Spring, but things are subtly different in the world of Java EE.
Tutorial Chapter 2 – Easier Development and Maintenance
Tired of wiring in an id
, and timestamp
field into all of your Hibernate objects? There’s an easy way to solve this pain once and for all of your classes. Avoid code-repetition: today’s article focuses on using Hibernate Annotations to map common fields into one mapped superclass.
If you have not done so already, and need to get a bare bones hibernate application up and running, this guide
should get you up and running in a few minutes.
Is there light at the end of the tunnel?
So I’m sure I’m not alone here, when I say that Hibernate can be frustrating, difficult to learn, and may even feel like to use it means to give up on some design principles that have been proven by many.
When you first begin, it feels like there are holes, inconsistencies, and problems that send you running home to the familiar behavior of plain SQL. But, I don’t think it’s time to give up on Hibernate yet.
Keep in mind that I am a relatively new Hibernate user, I consider myself somewhat experienced with software development, design patterns, principles, and best practices. If this sounds like you, read on…