Hi,
I have a problem with the column names generated for the Entity class with a composite primary key. I have defined an EmployeePK class and used the IdClass annotation to map it to the Employee Entity. But the columns generated in the database for the @Id annotated fields are not as per the names specfied in the @Column annotation, but are being created with the bean property names of the Primary Key class.
...TABLE `employee` (
`lastName` varchar(255) NOT NULL,
`SSN` varchar(255) NOT NULL,
`FIRST_NAME` varchar(255) default NULL,
`LOCATION` varchar(255) default NULL,
PRIMARY KEY (`lastName`,`SSN`)
) ...
I am using JPA with hibernate 3.1.3 as my persitence provider and for MySQL with MySQLDialect. I want have to the column names for lastName as LAST_NAME and SSN as SOCIAL_SECURITY_NO in the database.
Can anyone here please help me overcome this problem. I have tried using the AttributeOverride, many examples seem to suggest that it can be used only with Embeddable Annotation, but I do need to have the basic bean properties within the entity class. So can anyone please help to overcome the problem without the embedding the Primary Key class in my Entity.
Thank You.
The following is my code.
Code:
public class EmployeePK implements Serializable {
private String lastName;
private String SSN;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getSSN() {
return SSN;
}
public void setSSN(String ssn) {
SSN = ssn;
}
..............
}
@Entity
@Table(name = "EMPLOYEE", catalog = "cchs", uniqueConstraints = {})
@IdClass(EmployeePK.class)
public class Employee {
private String firstName;
private String lastName;
private String SSN;
private String location;
@Column(name = "FIRST_NAME", unique = false, nullable = true, insertable = true, updatable = true)
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Id
@Column(name = "LAST_NAME", unique = false, nullable = true, insertable = true, updatable = true)
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Id
@Column(name = "SOCIAL_SECURITY_NO", unique = false, nullable = true, insertable = true, updatable = true)
public String getSSN() {
return SSN;
}
public void setSSN(String ssn) {
SSN = ssn;
}
.....
}