public void setIdCard(IdCard idCard) {
this.idCard = idCard;
}
}
IdCard
/**
* 身份证(通过外键实现一对一关系)
* @author Administrator
*/
// 屏蔽缺少“serialVersionUID”定义警告
@SuppressWarnings("serial")
// 指明实体Bean名,默认值是类名
@Entity(name = "IdCard")
// 实体对应的数据表 name表名;uniqueConstraints唯一约束性;主键
@Table(name = "t_idcard", uniqueConstraints = { @UniqueConstraint(columnNames = {
"id" }) })
public class IdCard implements Serializable {
private Integer id;
private String cardNo;
private Person person;
@Id
// 主键唯一标识
@Column(name = "id")
// 字段名
@GeneratedValue(strategy = GenerationType.AUTO)
// 自动增加
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "cardNo", length = 32, nullable = false)
//name字段名,length字段最大字符长度,nullable是否允许为空,precision字段精度,scale小数位
数
public String getCardNo() {
return cardNo;
}
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
// 表示该属性并非一个到数据库表的字段的映射,ORM框架将忽略该属性
@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, mappedBy =
"idCard")
public Person getPerson() {
return person;
}
第 5 页 共 23 页