我正在做一些学术任务,但我被困住了。情况如下:
我有三个简单的数据库表和从它们生成的Java @Entity 类。
表标记:
STUDENT_ID (PK)
SUBJECT_ID (PK)
MARK
public class Mark implements Serializable {
private BigDecimal mark;
@Id
@Column(name = "STUDENT_ID", nullable = false, insertable = false, updatable = false)
private BigDecimal studentId;
@Id
@Column(name = "SUBJECT_ID", nullable = false, insertable = false, updatable = false)
private BigDecimal subjectId;
@ManyToOne
@JoinColumn(name = "SUBJECT_ID")
private Subject subject;
@ManyToOne
@JoinColumn(name = "STUDENT_ID")
private Student student;
(...)
}
表学生:
INDEX_NO (PK)
FNAME
LNAME
FACULTY_ID
public class Student implements Serializable {
@Column(name = "FACULTY_ID", nullable = false)
private BigDecimal facultyId;
@Column(nullable = false, length = 20)
private String fname;
@Id
@Column(name = "INDEX_NO", nullable = false)
private BigDecimal indexNo;
@Column(nullable = false, length = 20)
private String lname;
@OneToMany(mappedBy = "student")
private List<Mark> marksList1;
(...)
}
表学生:
ID (PK)
NAME
public class Subject implements Serializable {
@Id
@Column(nullable = false)
private BigDecimal id;
@Column(nullable = false, length = 60)
private String name;
@OneToMany(mappedBy = "subject")
private List<Mark> marksList;
(...)
}
任务是获得两个列表:
1. 尚未获得所有科目分数的学生列表。
2. 特定学生不得分的科目清单。
我不太擅长 SQL,所以查询构造有问题。它可以通过任何类似 JPA 的方式来解决,即 JPQL、Criteria API。
所以我请你帮忙。
感谢您的关注。