如何在休眠的两个实体中映射,其中一个实体具有带有3个字段的EmbeddedId?

时间:2018-09-05 07:27:57

标签: hibernate hibernate-mapping

第一个实体是:

@Entity
@Table(name = "POL_STN_MASTER")
public class POL_STN_MASTER implements java.io.Serializable{

@EmbeddedId
private PolStationEmbadedID polStationId;

@Column(name = "POL_STN_NM")
private String polStationName;
//getter and setter
}

EmbededID为:

@Embeddable
public class PolStationEmbadedID implements Serializable {

@Column(name = "DIST_CD")
 private String distCd;
@Column(name = "SUB_DIV_CD")
 private String subDivCD;
 @Column(name = "POL_STN_CD")
 private String polStnCD;
 //getter and setter
}

下一个实体是:

@Entity
@Table(name = "PRINCIPAL_INFO")
public class Principal_info implements Serializable {
@Id
@Column(name="ENROL_NO")
private String enrolNo;
 @Column(name = "DIST_CD")
 private String dist_cd;
 @Column(name = "SUB_DIV_CD")
 private String sub_div_cd;
 @Column(name = "POL_STN_CD")
 private String pol_st_cd;
 @Column(name = "FIRST_NM")
private String f_name;
@Column(name = "MIDDLE_NM")
private String m_name;
@Column(name = "LAST_NM")
private String l_name;
//getter and setter
}

我如何将实体'POL_STN_MASTER'和'Principal_info'与PolStationEmbadedID以及三个字段'dist_cd','sub_div_cd'和'pol_st_cd'映射??

请帮助。预先感谢。

0 个答案:

没有答案