【问题标题】:Find record by one of the composite primary keys通过复合主键之一查找记录
【发布时间】: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 中怎么可能?

【问题讨论】:

标签: java database hibernate


【解决方案1】:

尝试以下操作:

Criteria criteria = session.createCriteria(Student.class);
criteria.add(Restrictions.eq("student_id", student_id));
criteria.add(Restrictions.eq("course_code", course_code));
List list = criteria.list();

【讨论】:

    猜你喜欢
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 2012-08-19
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多