JPA在实体的映射中重复了列

时间:2018-06-03 16:16:25

标签: java hibernate jpa

我添加了一个新的OneToMany关系,看起来是错误:

ERROR [stderr] (main)     Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: org.udg.pds.simpleapp_javaee.model.Comment column: id (should be mapped with insert=\"false\" update=\"false\")"}}

我希望从Movie到UserMovieValoration和Comment有两个关系OneToMany。 那是我的代码:

@Entity
public class Movie implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@JsonView(Views.Private.class)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@JsonView(Views.Private.class)
private String name;
private Long year;
private String sinopsis;
private Long duration;
private String idioma;
private String trailer;

@OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, cascade= CascadeType.ALL, mappedBy = "movie")
@JsonIgnore
Set<UserMovieValoration> userMovieValorations =  new HashSet<>();

@OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="movie")
private List<Comment> comments = new ArrayList<>();

评论关系产生错误。我怎么解决它。

那是我的评论代码,我与电影有许多关系。

@Entity
public class Comment implements Serializable {
/**
 * Default value included to remove warning. Remove or modify at will. *
 */
private static final long serialVersionUID = 1L;


public Comment() {
}


public Comment(String comentari){
    this.comentari = comentari;
    this.date = new Date();
}

@Id
@JsonView(Views.Private.class)
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;

@JsonView(Views.Private.class)
private String comentari;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private Date date;



@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id")
private Movie movie;

}

1 个答案:

答案 0 :(得分:0)

像这样重命名列

@ManyToOne(取= FetchType.LAZY) @JoinColumn(名称=&#34; movie_id&#34) 私人电影电影