Chapter 17

Using Hibernate

Hibernate is a tool built specifically for managing the mapping between Java objects and database tables, usually referred to as Object/Relational Mapping, or ORM.

This chapter builds upon a sample database schema for a box office application. The application manages tickets for customers for different events, at different venues. Figure 17-1 shows the structure of the database.

Using Hibernate

How do you create Java objects using Hibernate?

Hibernate is a tool for mapping database relations to objects, so it makes sense to have domain objects for these entities. The classes are simple Plain Old Java Objects, or POJOs, and they simply match their corresponding database table. For instance, Listing 17-1 shows the class for the people table.

Listing 17-1: The Person class

public class Person { private int id; private String name; private String address; public Person() { // default no-arg constructor } public Person(int id, String name, String address) { this.id = id; this.name = name; this.address = address; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } @Override public String toString() { return ...

Get Java Programming Interviews Exposed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.