JPA自定义查询从多个表中删除

JPA Custom query Delete from multiple tables

我有一个自定义查询,用于从 2 个表中删除记录,如下所示

@Repository
public interface RoamingStatusHistoryRepository extends JpaRepository<RoamingStatusHistory, String> {
    @Query("DELETE rsh,rs from RoamingStatusHistory rsh inner join RoamingStatus rs on rsh.msisdn = rs.msisdn where TIMEDIFF(NOW(),rsh.createdDate)>'00:00:30'")
    public List<Date> deleteByDate();
}

但是在 DELETE IntelliJ 说 from expected got rsh 并且在 rsh 之后出现错误说 alias definition or WHERE expected, got ','

如何解决这个问题。上网查了没找到解决方法

我假设此查询是原生 SQL 查询,因此您必须添加 nativeQuery = true

@Repository
public interface RoamingStatusHistoryRepository extends JpaRepository<RoamingStatusHistory, String> {

    @Query("DELETE rsh,rs from RoamingStatusHistory rsh inner join RoamingStatus rs on rsh.msisdn = rs.msisdn where TIMEDIFF(NOW(),rsh.createdDate)>'00:00:30'",
           nativeQuery = true)
    public List<Date> deleteByDate();
}