关系table1_table2不存在Postgres

时间:2014-09-22 12:05:16

标签: spring hibernate postgresql spring-mvc

我目前正在使用Spring-MVC和hibernate。我在数据库,table1和table2中有2个表。 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;
}

1 个答案:

答案 0 :(得分:2)

@oneToMany 是单向关系  所以你只能用JPA来做。 因此,您需要使用oneToMany替换以下行。

@OneToMany(mappedBy="user",cascade = CascadeType.ALL, orphanRemoval = true)
相关问题