【发布时间】:2018-05-29 21:12:48
【问题描述】:
我的代码中有以下结构:
用户有一个最喜欢的电视节目列表,一个电视节目有一个季节列表,一个季节有一个剧集列表。
用户
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id", updatable = false, nullable = false)
private int id;
@OneToMany(mappedBy = "tvshows", fetch = FetchType.EAGER)
private List<TvShow> favourites;
/// everything else removed for clarity
}
电视节目
@Entity
@Table(name = "tvshows")
public class TvShow {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "tvShow_id", updatable = false, nullable = false)
private int id;
@OneToMany(mappedBy = "tvshows", fetch = FetchType.EAGER)
private List<Season> seasons;
/// everything else removed for clarity
}
季节
@Entity
@Table(name = "seasons")
public class Season{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "season_id", updatable = false, nullable = false)
private int id;
@OneToMany(mappedBy = "seasons", fetch = FetchType.EAGER)
private List<Episode> episodes;
/// everything else removed for clarity
}
应用程序不会启动并显示以下错误消息:
mappedBy reference an unknown target entity property: com.gcimpoies.project.model.Season.seasons in com.gcimpoies.project.model.TvShow.seasons
还有,
Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.gcimpoies.project.model.Season.seasons in com.gcimpoies.project.model.TvShow.seasons
我很确定我只是缺少正确的属性名称(mappedBy 的参数),但我不知道我做错了什么。
提前致谢!
【问题讨论】:
-
您是在建立单向还是双向关系?
-
我不知道它们之间的区别,但我想是双向的。
标签: java hibernate hibernate-mapping