I am working on an existing schema where a table has a composite primary key with one value autogenerated and another Id assigned. Below is the code:
@Entity
@Table(name = "emp_details")
public class Emp implements Serializable {
private Long id;
private String bank_emp_id;
@Id
@GeneratedValue
@Column(name = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Id
@Column(name = "bank_emp_id")
public String getBank_emp_id() {
return bank_emp_id;
}
public void setBank_emp_id(String bank_emp_id) {
this.bank_emp_id = bank_emp_id;
}
}
On trying to add a record, the insert statement is failing with error:
Field 'bank_emp_id' doesn't have a default value org.hibernate.exception.GenericJDBCException: could not insert
On further analysis, it looks like the insert statement doesn't include the column bank_emp_id.
Please suggest any changes if required.