Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

hibernate - JPA derived query IsLessThan filter not working with java.sql.Timstamp

when using Timestamp in my entity and making a derived query for that, then the resultset is empty in that case.

My Entity is :-

@Data
@Entity
public class RetryCandidate {
@Id
private String extId;
rivate transient int maxAllowedRetries;
private Status status = Status.RETRY_PENDING;
@Embedded
private ClientCallbackMetadata clientCallbackMetadata;
@CreationTimestamp
@Column(nullable = false, updatable = false)
private Timestamp createdDateTime;
@UpdateTimestamp
private Timestamp updatedDateTime;

}

Repository method:-

 Page<RetryCandidate> findByStatusAndUpdatedDateTimeIsBefore(Status status, Timestamp timestamp, Pageable pageable);

Derived JPA query(select columns removed):-

 select
    retrycandi0_.ext_id as ext_id2_0_
from
    retry_candidate retrycandi0_ 
where
    retrycandi0_.status=? 
    and retrycandi0_.updated_date_time<? 
order by
    retrycandi0_.updated_date_time asc limit ?

Values I'm passing in it:-

 binding parameter [1] as [INTEGER] - [0]
 binding parameter [2] as [TIMESTAMP] - [2021-01-29 09:13:00.011]

Sample postgres data:-

ext_id                                 status   updated_date_time
MGb070c5ed-50c5-4a53-96d9-aed6eece09af  0       2021-01-29 06:18:11
MG0fe4c8cc-350c-44a0-9769-030950522d85  0       2021-01-29 06:18:11
MG8821dd92-72b5-4feb-b1ca-592475007332  0       2021-01-29 06:18:12
MG096f9657-632f-4819-a36a-e42522bb3fa4  0       2021-01-29 06:18:12

This above code gives me empty resultset when it runs, and the query which hibernate generates from above query is manually running in postgres directly, can't find out what's the issue.

question from:https://stackoverflow.com/questions/65951672/jpa-derived-query-islessthan-filter-not-working-with-java-sql-timstamp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...