【问题标题】:JPA repeated column in mapping for entityJPA在实体映射中重复列
【发布时间】:2018-06-03 16:16:24
【问题描述】:

我添加了一个新的 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<>();

cmets 关系产生错误。我该如何解决它。

这是我的评论代码,我与 Movie 有 ManyToOne 关系。

@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;

}

【问题讨论】:

  • 评论实体长什么样?
  • 错误信息明确表示问题出在 Comment 实体中。但是您没有发布任何内容。
  • 我认为您在 Comment 实体中添加了两个名为 id 的列。一个是简单的Private Long id,另一个是@JoinColumn(name=id),实际上应该是@JoinColumn(name=movie_id)
  • 对不起,我刚刚添加了评论代码。

标签: java hibernate jpa


【解决方案1】:

像这样重命名列

@ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="movie_id") 私人电影电影

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 2019-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 1970-01-01
    相关资源
    最近更新 更多