Hibernate ORA-02292: 违反完整性约束 (ROOT.SYS_C007062) - 找到子记录
Hibernate ORA-02292: integrity constraint (ROOT.SYS_C007062) violated - child record found
我下面有休眠实体:
@Entity
@Table(name = "News")
public final class News implements Serializable, IEntity {
private static final long serialVersionUID = 3773281197317274020L;
@Id
@SequenceGenerator(name = "NEWS_SEQ_GEN", sequenceName = "NEWS_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "NEWS_SEQ_GEN")
@Column(name = "NEWS_ID", precision = 0)
private Long newsId; // Primary key
@Column(name = "TITLE")
private String title;
@Column(name = "SHORT_TEXT")
private String shortText;
@Column(name = "FULL_TEXT")
private String fullText;
@Temporal(TemporalType.DATE)
@Column(name = "CREATION_DATE")
private Date creationDate;
@Temporal(TemporalType.DATE)
@Column(name = "MODIFICATION_DATE")
private Date modificationDate;
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
@JoinColumn(name = "NEWS_ID", updatable = false, referencedColumnName = "NEWS_ID")
@OrderBy("creationDate ASC")
private List<Comment> commentsList;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "NEWS_TAG", joinColumns = { @JoinColumn(name = "NEWS_ID") }, inverseJoinColumns = { @JoinColumn(name = "TAG_ID") })
private Set<Tag> tagSet;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "NEWS_AUTHOR", joinColumns = { @JoinColumn(name = "NEWS_ID") }, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_ID") })
private Set<Author> author;
第二个:
@SequenceGenerator(name = "COMMENTS_SEQ", sequenceName = "COMMENTS_SEQ")
@Entity
@Table(name = "Comments")
public class Comment implements Serializable, IEntity {
private static final long serialVersionUID = 3431305873409011465L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "COMMENTS_SEQ")
@Column(name = "COMMENT_ID", precision = 0)
private Long commentId; // Primary key
@Column(name = "NEWS_ID")
private Long newsId;
@NotEmpty
@NotNull
@Column(name = "COMMENT_TEXT")
private String commentText;
@Temporal(TemporalType.DATE)
@Column(name = "CREATION_DATE")
private Date creationDate;
当我尝试删除实体 News 时,出现异常 ORA-02292:违反完整性约束 (ROOT.SYS_C007062) - 找到子记录。因此,如果我删除 属性 "updatable = false",它会尝试将可空字段设置为 属性 注释。我的错误是什么?请帮忙。
谢谢
因为你的新闻记录和评论是一对一或者一对多的关系。您很可能在定义 table 时没有指定 CACASDE ON DELETE 子句。为了删除实体 NEWS,您必须确保其所有相关评论记录都已删除或正在引用另一条 NEWS 记录。
基本上是 ORA 02292 异常的定义。
我下面有休眠实体:
@Entity
@Table(name = "News")
public final class News implements Serializable, IEntity {
private static final long serialVersionUID = 3773281197317274020L;
@Id
@SequenceGenerator(name = "NEWS_SEQ_GEN", sequenceName = "NEWS_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "NEWS_SEQ_GEN")
@Column(name = "NEWS_ID", precision = 0)
private Long newsId; // Primary key
@Column(name = "TITLE")
private String title;
@Column(name = "SHORT_TEXT")
private String shortText;
@Column(name = "FULL_TEXT")
private String fullText;
@Temporal(TemporalType.DATE)
@Column(name = "CREATION_DATE")
private Date creationDate;
@Temporal(TemporalType.DATE)
@Column(name = "MODIFICATION_DATE")
private Date modificationDate;
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
@JoinColumn(name = "NEWS_ID", updatable = false, referencedColumnName = "NEWS_ID")
@OrderBy("creationDate ASC")
private List<Comment> commentsList;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "NEWS_TAG", joinColumns = { @JoinColumn(name = "NEWS_ID") }, inverseJoinColumns = { @JoinColumn(name = "TAG_ID") })
private Set<Tag> tagSet;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "NEWS_AUTHOR", joinColumns = { @JoinColumn(name = "NEWS_ID") }, inverseJoinColumns = { @JoinColumn(name = "AUTHOR_ID") })
private Set<Author> author;
第二个:
@SequenceGenerator(name = "COMMENTS_SEQ", sequenceName = "COMMENTS_SEQ")
@Entity
@Table(name = "Comments")
public class Comment implements Serializable, IEntity {
private static final long serialVersionUID = 3431305873409011465L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "COMMENTS_SEQ")
@Column(name = "COMMENT_ID", precision = 0)
private Long commentId; // Primary key
@Column(name = "NEWS_ID")
private Long newsId;
@NotEmpty
@NotNull
@Column(name = "COMMENT_TEXT")
private String commentText;
@Temporal(TemporalType.DATE)
@Column(name = "CREATION_DATE")
private Date creationDate;
当我尝试删除实体 News 时,出现异常 ORA-02292:违反完整性约束 (ROOT.SYS_C007062) - 找到子记录。因此,如果我删除 属性 "updatable = false",它会尝试将可空字段设置为 属性 注释。我的错误是什么?请帮忙。 谢谢
因为你的新闻记录和评论是一对一或者一对多的关系。您很可能在定义 table 时没有指定 CACASDE ON DELETE 子句。为了删除实体 NEWS,您必须确保其所有相关评论记录都已删除或正在引用另一条 NEWS 记录。 基本上是 ORA 02292 异常的定义。