Using Hibernate 5.2.11-Final on SQLServer 2014 and jTDS driver.
I have an entity mapped like this:
Code:
@Entity
@Table(name="table1")
@SecondaryTable(name="table2", pkJoinColumns={
@PrimaryKeyJoinColumn(name="pk1", referencedColumnName="pk1"),
@PrimaryKeyJoinColumn(name="pk2", referencedColumnName="pk2")
})
public class MyPojo {
properties
}
I'm trying to delete this entity using the following JPA criteria:
Code:
CriteriaDelete<MyPojo> deleteCriteria = builder.createCriteriaDelete(MyPojo.class);
Root<MyPojo> fromMyPojo = deleteCriteria.from(MyPojo.class);
session.createQuery(deleteCriteria
.where(builder.equal(fromMyPojo.get("compositeId"), compositeIdInstance)))
.executeUpdate();
Hibernate generates series of statements:
creates a temporary table
populates it with the composite keys of the rows that will be deleted
executes the delete statement using the composite keys from the temporary table
drops the temporary table
I'm receiving the following error because of the delete statement:
Code:
Caused by: java.sql.SQLException: An expression of non-boolean type specified in a context where a condition is expected, near ','.
The delete statement is:
Code:
delete from table2
where (pk1, pk2) in (select pk1, pk2 from #table1)
Apparently the expression
where (pk1, pk2) in (select pk1, pk2 from #table1) is wrong.
I don't know what to do except throw a native sql query and delete both main and secondary tables.
What am I doing wrong?