在问答里和论坛中,经常看到有人问,怎样将使用本地SQL查询出来的结果映射为值对象的问题,这里就Hibernate中提供的方法做个结论。前提,这里没有使用属性的延迟加载技术。
假设有个值对像,如下:
Java代码
package test;
public class Person {
private Long id;
private String name;
private Long age;
private Long phone;
private String address;
public Person(Long id, String name, Long age, Long phone, String address) {
this.id = id;
this.name = name;
this.age = age;
this.phone = phone;
this.address = address;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getAge() {
return age;
}
public void setAge(Long age) {
this.age = age;
}
public Long getPhone() {
return phone;
}
public void setPhone(Long phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}