Hi,
Yes, this is how it was implemented in the original example. The only issue is that having an id used in the mapping for Person would mean that this parameter need to be defined as a property in the Person class. Person object would look like the following then:
Code:
Public class Person implements Serializable {
private String id;
private Employee employee;
private boolean hasBalance;
...... (getters and setters go here)
Public class Employee implements Serializable {
private String id;
private set hierarchyPolicies;
.....(getters and setters go here)
Even though
person.id refers to the same id as
person.employee.id I would need to (re)define it as a property in Person. It just seems odd to me to keep an extra property in Person just in order to get the mapping correct, since I can just use delegation Java in order to get my id from the employee object (person.getEmployee().getID())
It can be that I am wrong about the usage of one-to-one mapping here, but my first assumption was that mapping Person and Employee through the one-to-one mapping based on Primary Key would not require adding a new property in Person. All I need is to define a one-to-one mapping between Person and Employee based on the Primay key. In other words:
Code:
create table employee(
id VARCHAR(10) NOT NULL,
PRIMARY KEY(ID);
);
create table person(
id VARCHAR(10) NOT NULL,
PRIMARY KEY(ID);
FOREIGN KEY(ID)
REFERENCES employee(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);