我在使用嵌入式注释的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;
..
// getter and setter
}
但是,如果我尝试坚持学院与课程集合,
它给了我一个例外,
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的理解仍然很少,
我错了