【发布时间】:2022-08-21 15:37:55
【问题描述】:
JPA 在没有明确声明的唯一键变量的情况下加入 2 个表?
我有这两张桌子,学生可以在那里借很多书。
D B:
book
- id
- book_name
- student_id
student
-id
-student_name
JPA:
书实体 :
@Entity (\"book\")
class Book {
@Column (\"book_name\")
private String bookName;
@ManyToOne
@JoinColumn(name = \"student_id\", insertable=false, updatable=false)
private Student student;
..
..
}
和学生实体:
@Entity (\"student\")
class Student {
@Column (\"student_name\")
private String student_name;
@OneToMany(mappedBy = \"student\")
private List <Book> book;
..
}
出于某种原因,它抱怨
org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.Student with id 7402
-
你能展示一下它抛出异常的代码吗?还有几行堆栈跟踪?你为什么不使用@Id 字段?
标签: java jpa one-to-many