【发布时间】:2021-07-23 15:44:03
【问题描述】:
我有自联接表 CATEGORY。当我尝试删除子条目时,我的父条目 ae 也会被删除。我正在使用 Oracle 19.3 Db。
例如。
[
{
"id": 5,
"name": "parent",
"display_name": "parent",
"parent_id": 0
},
{
"id": 6,
"name": "child",
"display_name": "child",
"parent_id": 5
}
]
删除 6 的条目后,ID 为 5 的条目也将被删除。 我的班级
@Entity
@Table(name="CATEGORY")
public class Category implements Serializable {
@Id
@Column(name = "id", nullable = false, updatable = false, unique = true)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "name", nullable = false, updatable = true, unique = false)
private String name;
@Column(name = "display_name", nullable = false, updatable = true, unique = false)
private String displayName;
@NotFound(action = NotFoundAction.IGNORE)
@ManyToOne(cascade={CascadeType.ALL})
@JoinColumn(name="parent_id")
private Category parent;
//Setter and Getters and Constructors
Spring boot 的日志如下
2021-04-30 14:50:57.345 DEBUG 2588 --- [nio-8080-exec-3] org.hibernate.SQL :
delete
from
category
where
id=?
2021-04-30 14:50:57.345 TRACE 2588 --- [nio-8080-exec-3] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [4]
2021-04-30 14:50:57.403 DEBUG 2588 --- [nio-8080-exec-3] org.hibernate.SQL :
delete
from
category
where
id=?
2021-04-30 14:50:57.405 TRACE 2588 --- [nio-8080-exec-3] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [3]
2021-04-30 14:50:57.518 INFO 2588 --- [nio-8080-exec-3] c.e.c.service.impl.CategoryServiceImpl : Course category deleted with chain
【问题讨论】:
标签: java oracle spring-boot hibernate