JPA - shared composite primary key id is not working using @EmbeddedId
Joined: Jan 06, 2005
JPA Toplink - shared composite primary key id is not working using @EmbeddedId
This is the table script
CREATE TABLE Employee (
DEPARTMENT VARCHAR(255) NOT NULL,
STATE VARCHAR(255) NOT NULL,
my_salary BIGINT NOT NULL,
my_name VARCHAR(255), PRIMARY KEY (DEPARTMENT, STATE, my_salary))
The composite primary key is (DEPARTMENT, STATE, my_salary)
I have a AbstraceIdentiferPK.java which implements Serializable
protected long salary;
Can't help you with JPA, unfortunately, but are you sure about your choice of primary key?
You have put all the attributes of your Employee table - except the Employee's name (my_name) - into the PK. This means:
1. You cannot have two people with the same Department, State and Salary, but you can have two people with the same name.
2. You are indexing virtually the entire contents of your table.
3. The one column that looks it should be a key (my_name) is not indexed or part of a key.
If you're just messing around here with an arbitrary composite key to try out the JPA techniques, then of course this is not a problem. But if you think this is how to define your data and keys for real, then it is fairly catastrophic, and you would really need to read some basic database tutorials.
Also, are you sure you are reading the whole table e.g. "SELECT * FROM Employee" when you check the data? Your table script defines my_salary as NOT NULL, so it should not be possible to write a record with a NULL value in my_salary.
Joined: Oct 01, 2007
JPA does not support inheritance with Embeddables.
Either remove the inheritance, or don't use an EmbeddedId, use an IdClass instead and include the id fields in the employee.
Also, your Id does not seem like a very good Id, consider using a generated Id instead.