【发布时间】:2015-07-16 02:49:47
【问题描述】:
我在使用 Hibernate 框架的 Java Web 应用程序中的一个表中有复合主键:
例如:
@Embeddable
public class Student implements Serializable {
@Column(name = "student_id")
private String studentId;
@Column(name = "course_code")
private String courseCode;
}
我可以按两个字段过滤记录。但是,我只想搜索带有studentId 的记录。在 Hibernate 中怎么可能?
【问题讨论】:
-
你想用
studentId得到Student吗? -
是的,不管
courseCode。 -
没关系,我明白了!我在 HQL 上使用了
Student.studentId。 -
你按照我的回答通过
Hibernate Criteria做到这一点