Posted on 2009-06-20 19:20
胡娟 阅读(865)
评论(0) 编辑 收藏 所属分类:
JAVA
关系被维护端 IDCard
package com.hujuan.bean;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class IDCard {
private Integer id;
private String cardNo;
private People people;
public IDCard(){
}
public IDCard(String cardNo) {
this.cardNo = cardNo;
}
@OneToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE},
mappedBy="idCard")
public People getPeople() {
return people;
}
public void setPeople(People people) {
this.people = people;
}
@Id @GeneratedValue
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(length=18,nullable=false)
public String getCardNo() {
return cardNo;
}
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
}
关系维护端 people表
package com.hujuan.bean;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
@Entity
public class People {
private Integer id;
private String name;
private IDCard idCard;
public People(){
}
public People(String name) {
this.name = name;
}
@JoinColumn(name="idCard_id")
@OneToOne(cascade=CascadeType.ALL,optional=false)
public IDCard getIdCard() {
return idCard;
}
public void setIdCard(IDCard idCard) {
this.idCard = idCard;
}
@Id @GeneratedValue
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(length=10)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}