We are Borg
We are Borg

Reputation: 5311

Relation table1_table2 does not exist Postgres

I am currently working using Spring-MVC and hibernate. I have 2 tables in database, table1 and table2. Table1 has oneToMany relationship with table2. When I run the application with a query to delete a row from a Table1 and its children from Table2, I get an error saying, relation Table1_table2 does not exist.

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

Upvotes: 0

Views: 1121

Answers (1)

Harshal Patil
Harshal Patil

Reputation: 6759

@oneToMany is unidirectional relationship so you can do it using JPA only. So just you need to replace following line with your oneToMany.

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

Upvotes: 2

Related Questions