我想知道我应该做什么,因为我已经阅读了很多文章试图理解这一点,包括许多SO问题.我读过的任何东西都没有用这个钉在头上.
我想知道当使用级联规则和应用程序定义数据库时会发生什么,因为这将定义我是否应该采用以下方法.
create table foo(
id int unsigned not null auto_increment,
primary key(id)
);
create table bar(
id int unsigned not null auto_increment,
foo_id int unsigned not null,
primary key(id),
foreign key(foo_id) references foo(id) on delete cascade on update cascade
)
Run Code Online (Sandbox Code Playgroud)
@Entity
@Table(name = "foo")
public class Foo {
private int id;
private List<Bar> bars;
@Id
@GeneratedValue
@Column(name = "id")
public int getId() {
return id;
}
@OneToMany(mappedBy = "foo", cascade = {CascadeType.ALL})
public List<Bar> getBars() { …Run Code Online (Sandbox Code Playgroud)