我有这个命名查询:
select person from Person person , Citizen citizen
where person.id = citizen.id ;
我的实体成员具有以下方式
@Entity
@Table(name="PERSON")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PERSONID",insertable = false, updatable = false)
private long personId;
...
@OneToMany(fetch = FetchType.EAGER, mappedBy = "person", cascade = CascadeType.ALL)
@Cascade(value = org.hibernate.annotations.CascadeType.ALL)
@JsonManagedReference
private Set<Citizen> citizen= new HashSet<Citizen>();
}
实体公民
@Entity
public class Citizen{
...
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "PERSONID",insertable = false, updatable = false)
private long personId;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="PERSONID",insertable = false, updatable = false)
@JsonBackReference
private Person person;
private String name;
private String secondname;
private String phone;
}
我们的想法是执行命名查询,以检索包含每个人的公民列表的人员对象,只需在响应中使用name属性,不包括phone和secondname属性。有没有办法用HQL或Criteria做到这一点?