我在我的@Formula
一个实体上创建了一个带有注释的计算属性:
@Entity
@Table(name="PERSON")
public class Person {
@Searchable(name = "First name")
private String firstName;
@Column(name = "FIRST_NAME", nullable=false)
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@Searchable(name = "Last name")
private String lastName;
@Column(name = "LAST_NAME", nullable=false)
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Formula("FIRST_NAME || ' ' || LAST_NAME")
private String loFstLstName;
public String getLoFstLstName() {
return this.loFstLstName;
}
public void setLoFstLstName(String loFstLstName) {
this.loFstLstName = loFstLstName;
}
}
问题是我persons
在以下代码中的列表中只有空值:
Query q = entityManager.createQuery("SELECT loFstLstName FROM Person");
List persons = q.getResultList();
PERSON
FIRST_NAME
表包含在和LAST_NAME
字段中具有不同于 null 的值的记录。我将 Hibernate 3.3 与 PostgreSQL 8.4.9 一起使用。我究竟做错了什么?