@OneToOne单向关联,级联操作未被SQL查询删除。

huangapple go评论65阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年5月5日 03:58:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/61600556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定