使用内部联接从JPA查询中删除

时间:2014-04-24 21:39:37

标签: java mysql sql hibernate jpa

在尝试将此SQL更正为JPA存储库删除时,我一直收到错误。什么是正确的语法?

@Query("delete * from TS t inner join TSC c ON t.tenantId = c.id where t.id= ?1 AND c.endDate < ?2")
    void deleteTSWithExpiredDate(Long id, Date date);

Caused by: java.lang.IllegalArgumentException: node to traverse cannot be null!
    at org.hibernate.hql.internal.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:63)

另一个

    @Query("delete t.* from TS t inner join TSC c ON t.tenantId = c.id where t.id= ?1 AND c.endDate < ?2")
        void deleteTSWithExpiredDate(Long id, Date date);

expecting IDENT, found '*' near line 1, column 10 [delete t.* 

另一个

        @Query("delete t from TS t inner join TSC c ON t.tenantId = c.id where t.id= ?1 AND c.endDate < ?2")
            void deleteTSWithExpiredDate(Long id, Date date);

unexpected token: from near line 1, column 10 [delete t 

1 个答案:

答案 0 :(得分:0)

批量删除的语法是:

Query q = session.createQuery("delete Entity where id = :idParam");
// set params here
q.executeUpdate();

但是,从Hibernate documentation开始,在批量HQL查询中不能指定任何联接。子查询可以在where子句中使用,其中子查询本身可以包含连接。