Sviatlana
Sviatlana

Reputation: 1888

Hibernate ORA-02292: integrity constraint (ROOT.SYS_C007062) violated - child record found

I following have hibernate entities:

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

And the second:

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

When I'm trying to remove entity News, I get the exception ORA-02292: integrity constraint (ROOT.SYS_C007062) violated - child record found. So, if I remove the property "updatable = false" it tries to set nullable fields into property Comment. What is my mistake? Please, help. Thanks.

Upvotes: 0

Views: 6181

Answers (1)

Mark Stroeven
Mark Stroeven

Reputation: 696

Because your news records have a one to one or one to many relation with comments. You most likely did not specifcy a CACASDE ON DELETE clause while defining your table. in order to delete entity NEWS you have to make sure that all of its related comments records are deleted or are referencing another NEWS record. basicaly the definition of the ORA 02292 exception.

Upvotes: 1

Related Questions