我有两个表,Content
和 ContentType
每个内容都有一种内容类型
每种内容类型可能包含在许多内容中。
这是我的模型:
@Entity
@Table(name = "content")
public class Content implements Serializable {
public Content() {}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@ManyToOne
private ContentType contentType;
@NotNull
private String title;
//getter/setters }
ContentType
类:
@Entity
@Table(name = "contentType")
public class ContentType implements Serializable {
public ContentType() { }
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@NotNull
private String type;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "content")
private Set<Content> content;
//getter/setters }
但是我得到了这个异常:
No identifier specified for entity: content.ContentType
最佳答案
尝试进行以下更改。
mappedBy
应指向 Content
类中 ContentType
对象的名称。
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "contentType")
private Set<Content> content;
希望这有帮助。
关于java - 没有为实体指定标识符 : content. ContentType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34115188/