O'Reilly logo

Java Programming Interviews Exposed by Noel Markham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required