【发布时间】:2020-11-07 08:05:21
【问题描述】:
@Modifying(clearAutomatically = true)
@Transactional
@Query(value = "DELETE FROM transaction WHERE transaction_cre_sys_date <= (now() - interval 6 month)",nativeQuery = true)
void deleteSixMonthOldTransactions();
这是我的交易实体。我想删除超过 6 个月的记录
public class Transaction {
private Integer id;
private String transactionSource;
private String transactionId;
private LocalDateTime transactionCreSysDate;
}
【问题讨论】:
-
你有什么问题?
-
我想在没有原生查询的情况下使用这种方法。像 findByNationalId(String id)。像这样
-
此方法用于删除6个月以上的记录。 transaction_cre_sys_date 是日期变量。保存为 localDateTime 类型
-
我不明白。您要删除还是选择记录?
-
您的
Transaction实体长什么样?
标签: java spring-boot jpa spring-data-jpa jpql