Example database

This tutorial will use an example database with three tables, and three corresponding domain objects.

We use PostgreSQL syntax in the examples. Here is the DDL for our database:

CREATE SEQUENCE country_id;
CREATE SEQUENCE address_id;
CREATE SEQUENCE customer_id;

CREATE TABLE country (
    id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('country_id'),
    name TEXT
);

CREATE TABLE address (
    id INTEGER NOT NULL DEFAULT nextval('address_id'),
    street TEXT,
    zip TEXT,
    city TEXT,
    country INTEGER NOT NULL REFERENCES country(id)
);

CREATE TABLE customer (
    id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('customer_id'),
    name TEXT,
    email TEXT,
    delivery_address INTEGER NOT NULL REFERENCES address(id),
    billing_address INTEGER NOT NULL REFERENCES address(id)
);

And these are our corresponding domain objects, getters and setters omitted for brevity:

public class Country {
    private Integer id;
    private String name;
}

public class Address {
    private Integer id;
    private String street;
    private String zip;
    private String city;
    private Country country;
}

public class Customer {
    private Integer id;
    private String name;
    private String email;
    private Address deliveryAddress;
    private Address billingAddress;
}