Dan*_*elo 2 java postgresql spring jpa spring-mvc
我在 JPA 中使用自定义查询,它不允许我使用interval关键字。如果我不在- interval '7 days'查询中使用,它会提供正确的输出。
异常说:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: interval near line 1, column 214
@Query("select d from DomainName d , DomainNameReminder dr, Reseller r"+
" where d.reminder.id = dr.id "+
" and dr.secondNotification=current_date - interval '7 days' "+
" and r.checkParty=true "+
" and r.id = d.invoicingParty.id ")
public List<Object> findDomainsBySecondNotificationDate();
Run Code Online (Sandbox Code Playgroud)
此查询基本上带来了今天之前 7 天具有第二个通知日期的所有记录。
我的接口被声明为
public interface DomainNameRepository extends JpaRepository<DomainName, Long>,
QueryDslPredicateExecutor<DomainName> {
Run Code Online (Sandbox Code Playgroud)
我的查询在 中给出了正确的输出pgadmin postgresql client,我很惊讶为什么我不能在这里使用关键字。
这解决了我的问题。
我使用nativeQuery=true并使用了我在 postgresql 中执行的查询。也想和别人分享。
@Query( nativeQuery = true, value = "select domain_name.* from domain_name, domain_name_reminder, reseller " +
"where domain_name.reminder_id = domain_name_reminder.id " +
"and domain_name_reminder.second_notification=current_date - interval ':totalDays days' " +
"and reseller.myCheck=true " +
"and reseller.id = domain_name.invoicing_party_id ")
public List<DomainName> findDomainsBySecondNotificationDate(@Param("totalDays")Integer totalDays);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1144 次 |
| 最近记录: |