Person.java
1 package cn.itcast.hiberate.sh.domain.onetoone; 2 3 import java.io.Serializable; 4 import java.util.Set; 5 6 public class Person implements Serializable{ 7 private Long cid; 8 private String cname; 9 private String description;10 11 public Long getCid() {12 return cid;13 }14 15 public void setCid(Long cid) {16 this.cid = cid;17 }18 19 public String getCname() {20 return cname;21 }22 23 public void setCname(String cname) {24 this.cname = cname;25 }26 27 public String getDescription() {28 return description;29 }30 31 public void setDescription(String description) {32 this.description = description;33 }34 35 public Address getAddress() {36 return address;37 }38 39 public void setAddress(Address address) {40 this.address = address;41 }42 43 private Address address;44 }
Person.hbm.xml
1 2 45 6 407 98 10 11 12 30 31 34 3935 3736 38
Address.java
1 package cn.itcast.hiberate.sh.domain.onetoone; 2 3 import java.io.Serializable; 4 5 public class Address implements Serializable{ 6 private Long sid; 7 private String sname; 8 9 private Person person;10 11 12 public Person getPerson() {13 return person;14 }15 public void setPerson(Person person) {16 this.person = person;17 }18 public Long getSid() {19 return sid;20 }21 public void setSid(Long sid) {22 this.sid = sid;23 }24 public String getSname() {25 return sname;26 }27 public void setSname(String sname) {28 this.sname = sname;29 }30 public String getDescription() {31 return description;32 }33 public void setDescription(String description) {34 this.description = description;35 }36 private String description;37 }
Address.hbm.xml 外键唯一
1 2 45 6 177 98 10 11 15 16