2014-09-22 96 views
0

我目前正在使用Spring-MVC和hibernate。我在数据库,表1和表2中有2个表。 Table1与table2有一对多的关系。当我使用查询从Table1及其Table2中的子项中删除一行的应用程序时,出现错误,表示关系Table1_table2不存在。关系table1_table2不存在Postgres

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; 
} 

回答

2

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

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

我刚开始再做一次。会做的。谢谢。 – 2014-09-23 06:57:41

+0

欢迎大哥 – 2014-09-23 08:39:57

相关问题