Given the following tables:
CREATE TABLE Employees
(
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
birth_date DATE NOT NULL,
PRIMARY KEY (first_name, last_name)
);
CREATE TABLE Managers
(
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
salary INTEGER NOT NULL,
total_bonus INTEGER NULL,
PRIMARY KEY (first_name, last_name),
CONSTRAINT managers_employees_fk FOREIGN KEY (first_name, last_name) REFERENCES Employees (first_name, last_name)
);
CREATE TABLE Workers
(
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
wage INTEGER NOT NULL,
PRIMARY KEY (first_name, last_name),
CONSTRAINT workers_employees_fk FOREIGN KEY (first_name, last_name) REFERENCES Employees (first_name, last_name)
);
how would you implement the entity and composite primary key classes using JPA 1.0 @IdClass annotations?
Sub questions arising are:
- Do sub classes define their own ID classes?
- If so, do they inherit from the super class' ID class?
- Do sub classes get @IdClass annotations?
Note the question is intentionally naive. I'd like to see the class declarations, properties with field access annota开发者_JAVA技巧tions without getters and setters will probably suffice.
Thanks
PK is defined in the root of the inheritance tree. The root defines all.
The spec says The primary key must be defined on the entity class that is the root of the entity hierarchy or on a mapped superclass that is a (direct or indirect) superclass of all entity classes in the entity hierarchy. The primary key must be defined exactly once in an entity hierarchy.
精彩评论