java collection join_java – @ElementCollection @CollectionTable在一对多映射中
我在使用嵌入式注釋的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的理解仍然很少,
我錯了
總結
以上是生活随笔為你收集整理的java collection join_java – @ElementCollection @CollectionTable在一对多映射中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java简单课程设计_!高分跪求帮忙写一
- 下一篇: 代码讲解java_主要代码的讲解