我正在尝试使用嵌入式注释在 JPA 中建立关系,但我无法成功运行它,
这里我的数据库sql脚本如下,
create table TBL_COLLEGE(
id integer primary key generated always as identity (start with 1000, increment by 5),
name varchar(50)
)
create table TBL_COURSE(
Id integer primary key generated always as identity (start with 10, increment by 1),
college_Id integer references TBL_COLLEGE,
name varchar(50)
)
下面是 JPA 的代码,
@Embeddable
public class Course {
...
...
..
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name="ID")
private Integer courseId;
@Column(name="NAME")
private String courseName;
@Column(name="COLLEGE_ID")
private Integer collegeId;
....
// getter and setter
}
这是学院映射,
@Entity
@Table(name="TBL_COLLEGE")
public class College implements Serializable{
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name="ID")
private Integer collegeId;
...
..
@ElementCollection(targetClass=Course.class,fetch= FetchType.LAZY)
@CollectionTable(name="TBL_COURSE",joinColumns=@JoinColumn(name="COLLEGE_ID"))
private Set<Course> course;
..
// getter and setter
}
但是,如果我尝试使用 Courses 集合来坚持 College,它会给我一个例外,
ERROR: HCANN000002: An assertion failure occurred (this may indicate a bug in Hibernate)
org.hibernate.annotations.common.AssertionFailure: Declaring class is not found in the inheritance state hierarchy: com.entities.Course
....
..
你能告诉我我的方法是否错误,或者我对@CollectionTable 的理解仍然很少,我错了吗