【问题标题】:Relation table1_table2 does not exist Postgres关系 table1_table2 不存在 Postgres
【发布时间】:2014-09-22 12:05:15
【问题描述】:

我目前正在使用 Spring-MVC 和休眠。我在数据库中有 2 个表,table1 和 table2。 Table1 与 table2 具有 oneToMany 关系。当我使用查询运行应用程序以从 Table1 中删除一行及其从 Table2 中的子项时,我收到一条错误消息,指出关系 Table1_table2 不存在。

Code :
@Table(name="table1")
class user{
    @OneToMany
    public Set<Accounts> accounts;
    //Remove method
     Query query = session.createQuery("From User as u LEFT JOIN FETCH u.accounts WHERE u.id="+id)
     //then I use a for loop to go through the Accoutns and remove the accounts.
}
@Table(name="Table2")
class accounts{
    @manyToOne
    public User user;
}

【问题讨论】:

    标签: spring hibernate postgresql spring-mvc


    【解决方案1】:

    @oneToMany是单向关系 所以你只能使用 JPA 来做到这一点。 所以你只需要用你的 oneToMany 替换以下行。

    @OneToMany(mappedBy="user",cascade = CascadeType.ALL, orphanRemoval = true)
    

    【讨论】:

    • 我刚刚又开始这样做了。会做的。谢谢。
    猜你喜欢
    • 2019-08-02
    • 2020-04-09
    • 2018-12-02
    • 2018-05-15
    • 2015-08-13
    • 1970-01-01
    • 2021-01-13
    • 2016-04-11
    • 2016-07-05
    相关资源
    最近更新 更多