How does Hibernate deal Composite Key to auto generate the a column value. I have My entity as below. In the id variable, I need one of the value to be auto-generated. how do we auto generated key when dealing with composite primary key.
Code:
@Entity
@Table(name="co_dmd_adjt_id "
,schema="public"
)
public class CoDmdAdjtId implements java.io.Serializable {
private CoDmdAdjtId id;
private Character cdActn;
private Date effDate;
private Date expDate;
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name="idBsnUn", column=@Column(name="id_bsn_un", nullable=false, length=40) ),
@AttributeOverride(name="idAdjtFct", column=@Column(name="id_adjt_fct", nullable=false) ) } )
public CoDmdAdjtId getId() {
return this.id;
}
public void setId(CoDmdAdjtId id) {
this.id = id;
}
Code:
@Embeddable
public class CoDmdAdjtId implements java.io.Serializable {
private String idBsnUn;
private Integer idAdjtFct;
public CoDmdAdjtId() {
}
@Column(name="id_bsn_un", nullable=false, length=40)
public String getIdBsnUn() {
return this.idBsnUn;
}
public void setIdBsnUn(String idBsnUn) {
this.idBsnUn = idBsnUn;
}
@Column(name="id_adjt_fct", nullable=false)
@GeneratedValue(strategy=GenerationType.AUTO)
public Integer getIdAdjtFct() {
return this.idAdjtFct;
}
public void setIdAdjtFct(Integer idAdjtFct) {
this.idAdjtFct = idAdjtFct;
}
}