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
@Column(name="my_salary")
protected long salary;
public long getSalary() {
return salary;
}
EmployeeIdPK extends AbstraceIdentiferPK
@Column(name="department")
protected String department;
@Column(name="state")
protected String state;
public EmployeeId(String department, String state, long salary) {
this.department = department;
this.state = state;
this.salary = salary;
}
In the Employee.java
@EmbeddedId
private EmployeeId id;
@Column(name="my_name")
private String name;
public Employee(EmployeeId id) {
this.id = id;
}
public EmployeeId getId() {
return id;
}
In the JPAMain.java
es.createEmployee(new EmployeeId("marketing", "MA", 1000000), "shekar");
es.createEmployee(new EmployeeId("marketing", "NY",800000), "Bill Clinton");
es.createEmployee(new EmployeeId("engineering", "MA",700000),"Angela Caicedo");
This is the peristed output
******** Table: EMPLOYEE *******
+--------------------------------+--------------------------------+--------------------------------+
| MY_NAME | DEPARTMENT | STATE |
+--------------------------------+--------------------------------+--------------------------------+
| Angela Caicedo | engineering | MA |
| shekar | marketing | MA |
| Bill Clinton | marketing | NY |
+--------------------------------+--------------------------------+--------------------------------+
The issue , the salary is not persisted in the database
Please let me know if i m missing anything.