我有2個實體 黑名單標準休眠
public class BlackList {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne
@JoinColumn(name = "applicant_id", unique = true)
private Applicant applicant;
和
public class Applicant {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "number", nullable = false, unique = true)
private String number;
請幫助我。如何創建標準得到我的數據的查詢:select applicant.number from black_list inner join applicant on black_list.applicant_id = applicant.id
public List<BlackList> getAll(){
Session session =sessionFactory.getCurrentSession();
ProjectionList projectionList = Projections.projectionList();
Criteria criteria = session.createCriteria(BlackList.class);
projectionList.add(Projections.property("applicant"));
criteria.setProjection(projectionList);
List res = criteria.list();
return res;
}
此方法返回ME/ID和數字/但我只需要數
,我們可以幫我寫這個? –