码迷,mamicode.com
首页 > Web开发 > 详细

hibernate联合主键 组合组件(component)

时间:2016-01-16 01:25:21      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

package db.domain;

/**
* PersonId entity. @author MyEclipse Persistence Tools
*/

public class PersonId implements java.io.Serializable {

// Fields

private String firstname;
private String lastname;

// Constructors

/** default constructor */
public PersonId() {
}

/** full constructor */
public PersonId(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}

// Property accessors

public String getFirstname() {
return this.firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return this.lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof PersonId))
return false;
PersonId castOther = (PersonId) other;

return ((this.getFirstname() == castOther.getFirstname()) || (this
.getFirstname() != null
&& castOther.getFirstname() != null && this.getFirstname()
.equals(castOther.getFirstname())))
&& ((this.getLastname() == castOther.getLastname()) || (this
.getLastname() != null
&& castOther.getLastname() != null && this
.getLastname().equals(castOther.getLastname())));
}

public int hashCode() {
int result = 17;

result = 37 * result
+ (getFirstname() == null ? 0 : this.getFirstname().hashCode());
result = 37 * result
+ (getLastname() == null ? 0 : this.getLastname().hashCode());
return result;
}

}

 

 

 

 

 

 

 

 

package db.domain;

/**
* Person entity. @author MyEclipse Persistence Tools
*/

public class Person implements java.io.Serializable {

// Fields

private PersonId id;
private String sex;
private Integer age;
private String birth;

// Constructors

/** default constructor */
public Person() {
}

/** minimal constructor */
public Person(PersonId id) {
this.id = id;
}

/** full constructor */
public Person(PersonId id, String sex, Integer age, String birth) {
this.id = id;
this.sex = sex;
this.age = age;
this.birth = birth;
}

// Property accessors

public PersonId getId() {
return this.id;
}

public void setId(PersonId id) {
this.id = id;
}

public String getSex() {
return this.sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public Integer getAge() {
return this.age;
}

public void setAge(Integer age) {
this.age = age;
}

public String getBirth() {
return this.birth;
}

public void setBirth(String birth) {
this.birth = birth;
}

}

 

 

<component name="address" class="Address">
<property name="postalCode" type="string">
<column name="postalCode" length="20" />
</property>
<property name="mobile" type="string">
<column name="mobile" length="20" />
</property>
</component>

hibernate联合主键 组合组件(component)

标签:

原文地址:http://www.cnblogs.com/hzzhero/p/5134792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!