Skip Headers

# Using Java

Previous

Next

Example: HistoryPolicy for One Table shows how to describe the schema shown in Table: Example Table for EMPLOYEE and Table: Example History Table EMPLOYEE_HIST using the TopLink `HistoryPolicy`:

HistoryPolicy for One Table

    HistoryPolicy policy = new HistoryPolicy();
    policy.addStartFieldName("ROW_START");
    policy.addEndFieldName("ROW_END");
    policy.addHistoryTableName("EMPLOYEE", "EMPLOYEE_HIST");
    // Assuming database triggers or stored procedures update history tables
    policy.setShouldHandleWrites(false);

    employeeDescriptor.setHistoryPolicy(policy);

You can specify more than one table with a `HistoryPolicy` as shown in Example: HistoryPolicy for Multiple Tables. In this example, all history tables have a start field named `ROW_START` but the `EMPLOYEE_HIST` and `SALARY_HIST` tables have different end fields. To avoid ambiguity, the end field names are prefixed with their respective history table names.

HistoryPolicy for Multiple Tables

    HistoryPolicy policy = new HistoryPolicy();
    policy.addStartFieldName("ROW_START");
    policy.addEndFieldName("EMPLOYEE_HIST.ROW_END");
    policy.addEndFieldName("SALARY_HIST.VALID_UNTIL");
    policy.addHistoryTableName("EMPLOYEE", "EMPLOYEE_HIST");
    policy.addHistoryTableName("SALARY", "SALARY_HIST");
    // Assuming database triggers or stored procedures update history tables
    policy.setShouldHandleWrites(false);

    employeeDescriptor.setHistoryPolicy(policy);