Database Design Rules

In fact, you can design your database as you wishes. PM will not complain about it. But to generate good looking pojos you should follow one of those two rules:

Rule 1: Casing

Casing is quite simple: tables should be defined using pascal case (every first word character in upper case). Use camel case for column names (first word in lower case, every first letter of following words in upper case).

Example

CREATE TABLE EmployeDepartment -- Pascal case
(
    id INT PRIMARY KEY,        -- Camel case
    employeeId INT,            -- Camel case
    departmentId INT           -- Camel case
);

Rule 2: Underscores (_)

This rule should be followed if your RDBMS does not keep casing information for your database structures. It's the case of Derby that saves everything in upper case. If your RDBMS falls in this category follow this rule:

split words with the underscore (_) character.

Example

CREATE TABLE employee_department
(
    id INT PRIMARY KEY,
    employee_id INT,
    department_id INT
);

Resulting Pojo

class EmployeeDepartment {

    private Integer departmentId = null;
    private Integer employeeId = null;
    private Integer id = new Integer(0);

    public EmployeeDepartment() {}

    public Integer getDepartmentId() {
        return this.departmentId;
    }

    public void setDepartmentId(Integer value) {
        this.departmentId = value;
    }

    public Integer getEmployeeId() {
        return this.employeeId;
    }

    public void setEmployeeId(Integer value) {
        this.employeeId = value;
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer value) {
        if (value == null) {
            throw new NullPointerException("The property id cannot be null.");
        }
        this.id = value;
    }
}