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

时间:2019-05-17 05:56:04

标签: spring-boot jpa crud

我有一个自定义查询,用于从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();
}

但是在删除IntelliJ说出预期中得到了rsh 之后,并且在rsh之后出现了一个错误,说出别名定义或期望中得到了','

如何解决此问题。在互联网上进行了研究,但找不到解决方法

1 个答案:

答案 0 :(得分:2)

我假设此查询是本机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();
}