Hibernate的一对一关系__教程 |
|
日期:2007-5-20 0:36:08 人气:63 [大 中 小] |
|
|
|
一对一关系的维护有两种,分为主键关联和唯一外键关联一对一关系的维护有两种,分为主键关联和唯一外键关联主键关联:(双向)(主控方) Person.javaPerson { private String username; //对被控方的引用 private Address address; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address= address; }}(被动方) Address.javaAddress{ private String addressName; //对主控方的引用 private Person person; public String getAddressName() { return addressName; } public void setAddressName(String addressName) { this.addressName= addressName; } public Person getPerson() { return person; } public void setPerson(Person person) { this.person= person; } public String toString() { return new ToStringBuilder(this). append("addressName", addressName). toString(); } public boolean equals(Object o) { if ( !(o instanceof Address) { return false; } Address rhs = (Address) o; return new EqualsBuilder() .appendSuper(super.equals(o))   |
|
出处:本站原创 作者:佚名 |
|
|