基于annotation的onetoone的配置
IDCard.java
package org.zttc.itat.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name="t_id_card") public class IDCard { private int id; private String no; private Person person; @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getNo() { return no; } public void setNo(String no) { this.no = no; } @OneToOne @JoinColumn(name="pid") public Person getPerson() { return person; } public void setPerson(Person person) { this.person = person; } }
Person.java
package org.zttc.itat.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @Table(name="t_person") public class Person { private int id; private String name; private IDCard idCard; @OneToOne(mappedBy="person") public IDCard getIdCard() { return idCard; } public void setIdCard(IDCard idCard) { this.idCard = idCard; } @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
时间: 2024-11-10 05:04:06