JPA命名查询不应该返回空数组

时间:2019-05-22 22:14:15

标签: spring-boot jpa named-query

我正在尝试从Springboot / JPA存储库中的Oracle数据库查询数字字段的最后5位数字。

在Oracle中,以下查询有效: Select * FROM DP1_Attachments Where trim(substr(dp1_submit_date_dp1_number, -5, 5)) = [a-five-digit-number]

我尝试实现以下内容:

ENTITY:

@IdClass(CompositeKey.class)
public class DP1Attachments {

    @Id
    private  Integer attachmentsFolder;
    @Id
    private  Integer attachmentNumber;

    private  Integer dp1SubmitDateDp1Number;
    private  String attachmentName;
    private  Integer attachmentSize;
    private  String attachmentType;

    @JsonFormat(pattern = "MM/dd/yyyy HH:mm")
    private LocalDateTime attachmentDate;
    private  String attachmentBy;
    private  Integer attachmentByUsersId;
    private  String attachmentActive;
    private  String modifiedBy;
    private  Integer modifiedByUsersId;
    @JsonFormat(pattern = "MM/dd/yyyy HH:mm")
    private  LocalDateTime modifiedDate;

存放


    @Query("SELECT a FROM DP1Attachments a WHERE trim(substring(a.dp1SubmitDateDp1Number, -5, 5)) = :dp1Number")
    List<DP1Attachments> queryByDp1SubmitDateDp1Number(@Param("dp1Number") String dp1Number);

}

服务

public List<DP1Attachments> getAttachmentsList (String dp1Number){
        return attachmentsRepository.queryByDp1SubmitDateDp1Number(dp1Number);
    }

控制器

    public ResponseEntity<?> getAttachmentsInFolder (@PathVariable String attachmentFolder){
        List<DP1Attachments>files = attachmentsService.getAttachmentsList(attachmentFolder);
        return new ResponseEntity<>(files, HttpStatus.OK);
    }

查询运行,但返回一个空数组。

我还尝试将子字符串更改为LIKE语句:

@Query("SELECT a FROM DP1Attachments a WHERE TO_CHAR(a.dp1SubmitDateDp1Number) like :dp1Number")
    List<DP1Attachments> queryByDp1SubmitDateDp1Number(@Param("dp1Number") String dp1Number);

服务更改为:

 public List<DP1Attachments> getAttachmentsList (String dp1Number){
        return attachmentsRepository.queryByDp1SubmitDateDp1Number("%" + dp1Number);
    }

这也会运行而没有错误,但返回一个空数组。

0 个答案:

没有答案