英文:
@OneToOne Uni directional with cascading didn’t delete by sql query
问题
<br>
我尝试创建两个表(主表和辅助表)<br>并使用@OneOnOne关系。(我正在使用Postgres)<br>
我像这样定义了主表:
Class Table1{
@GeneratedValue
@Id
@Column
private int Id;
@OneToOne(cascade =CasscadeType.ALL)
public Table2 table2;
我的问题是,当我尝试通过SQL查询删除表(从Table1中删除)时,数据从Table1中删除,但它没有从与Table1相关联的table2中删除行。
英文:
<br>
I tried to create two table (primary and secondary)<br> with @OneOnOne relation.(I’m using Postgres )<br>
I define the primery table like this:
Class Table1{
@GeneratedValue
@Id
@Column
private int Id;
@OneToOne(cascade =CasscadeType.ALL)
public Table2 table2;
My problem is when I try to delete the table by sql query (delete from Table1) the data delete from Table1 but it didn’t delete row from table2 which related to Table1
答案1
得分: 1
你可以尝试这样做:
@OneToMany(cascade=CascadeType.ALL)
英文:
You should try this:
@OneToMany(cascade=CascadeType.ALL)
专注分享java语言的经验与见解,让所有开发者获益!
评论