我正在尝试测试一个组合主键,不幸的是有些东西运行不正确。
包含组合主键的课程类
@Entity(name = "Course")
public class Course {
@EmbeddedId
private PkCourse pkCourse;
public Course() {}
public Course( PkCourse pkCourse) {
this.pkCourse = pkCourse;
}
public PkCourse getPkCourse() {
return pkCourse;
}
public void setPkCourse( PkCourse pkCourse ) {
this.pkCourse = pkCourse;
}
}
表示组合主键的类
@Embeddable
public class PkCourse implements Serializable {
@Column(name = "courseName")
private String courseName;
@Column(name = "courseGrade")
private Integer grade;
PkCourse(){
}
public PkCourse( String courseName, Integer grade ) {
this.courseName = courseName;
this.grade = grade;
}
public String getCourseName() {
return courseName;
}
public void setCourseName( String courseName ) {
this.courseName = courseName;
}
public Integer getGrade() {
return grade;
}
public void setGrade( Integer grade ) {
this.grade = grade;
}
@Override
public boolean equals( Object o ) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PkCourse pkCourse = (PkCourse) o;
return courseName.equals(pkCourse.courseName) &&
Objects.equals(grade, pkCourse.grade);
}
@Override
public int hashCode() {
return Objects.hash(courseName, grade);
}
}
我的测试程序
private void composedPrimaryKey() {
PkCourse composedPK = new PkCourse("database", 3);
Course course = new Course(composedPK);
courseRepository.save(course);
}
我的 jpa 存储库
public interface CourseRepository extends JpaRepository<Course, PkCourse> {
}
我得到的例外
原因:org.springframework.dao.InvalidDataAccessResourceUsageException:无法提取结果集;SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: 无法提取 ResultSet
Caused by: java.sql.SQLSyntaxErrorException: 表 'company.course' 不存在
慕婉清6462132
相关分类