I'm using PostgreSQL 9.6 with Hibernate 5.2.10 and have 3 entities:
@Entity
@Table(name = "entity1")
public class Entity1 {
@Id
private long id;
@ManyToOne
@JoinColumn(name = "entity2_id")
private Table2 table2;
}
@Entity
@Table(name = "entity2")
public class Entity2 {
@Id
private long id;
@ManyToOne
@JoinColumn(name = "entity3_id")
private Table3 table3;
}
@Entity
@Table(name = "entity3")
public class Entity3 {
@Id
private long id;
}
I need to all delete the occurencies of Entity1 when it joins Entity2 filtering by Entity3, like this:
em.createQuery("delete from Entity1 e where e.entity2.entity3 = :entity3")
And Hibernate generates the following SQL:
delete from entity1 cross join entity2 entity2_ where entity3_id=?
The problem is that PostgreSQL does not recognized the cross join and I didn't find any other way to do this (other than using native query).
PS: in the database all the tables have foreign keys.