我关注了hibernate实体:
@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;
当我尝试删除实体新闻时,我收到异常ORA-02292:违反了完整性约束(ROOT.SYS_C007062) - 找到了子记录。所以,如果我删除属性&#34; updatable = false&#34;它试图将可空字段设置为属性Comment。我的错是什么?请帮忙。 感谢。
答案 0 :(得分:1)
因为您的新闻记录与评论有一对一或一对多的关系。在定义表时,您很可能没有指定CACASDE ON DELETE子句。为了删除实体NEWS,您必须确保删除所有相关的注释记录或引用另一个NEWS记录。 基本上是ORA 02292异常的定义。