I have an entity Event which has fields startDate and endDate. I'd like to select only those events that have at most x days left to the their endDate. I want to do this in JPQL and with only one query. How can I do this?
Taking the difference of temporal fields in JPQL
2.7k Views Asked by Oleksandr Bondarenko At
1
There are 1 best solutions below
Related Questions in JPA
- Hibernate SQL Error: Missing FROM-clause entry for table "th1_1"
- JPA Hibernate OneToOne Mapping
- Problem While Fetching the Entity data and its related Entity data with JPA(Lazy Initialization Exception)
- Why does Hibernate execute two SELECT queries instead of one when using @ManyToOne(fetch = FetchType.EAGER)
- JPA Two primary key at owning side and One Foreign Key at the Child
- Approaches to persist enum in java
- Problem with inserting objects into database that have composite ids
- Unique index or primary key violation Spring JPA
- Concurrently open statements
- JPA SPECIFICATION WITH INTERFACE PROJECTIONS
- Conditional uniqness
- Spring JPA + Hibernate + Rest services + long time transactions
- JPA/Hibernate JpaSystemException: identifier of an instance of X was altered from Y to Z
- How to Revert Database Changes Made in a Session Without Using Transaction Management?
- Hibernate generic type handling
Related Questions in JPA-2.0
- Upgrading from Hibernate 4.x to 5.x producing SQLException Invalid Column Index
- Cannot create a table in H2 with a custom enum
- JPA criteria select multiple fields from subquery
- Spring boot 3, javax.persistence and entity scan
- Issue with Jpa and inheritance
- Joining pageable tables without relation using JPA criteria
- JPA ElementCollection foreign key mapping error
- JPA [EcliseLink]: Cannot change the type of an instance of parent A to subclass B In the single table inheritance
- SpringBoot JPA in MySQL
- In JPA2 and Java 10, how do I map the value of an enum to an @Enumerated column?
- can do this with JPA / Hibernate criteriabuilder
- JPA Criteria Subquery with select multiple colums and max() function
- How to properly / efficiently manage entity manager JPA Spring @Transactional for large datasets?
- Build a jpa specification query without retriving child entity data
- findAll() in spring boot
Related Questions in JPQL
- Transaction silently rolled back
- Problem While Fetching the Entity data and its related Entity data with JPA(Lazy Initialization Exception)
- @SqlResultSetMapping with ConstructorResult checks for all the field using BeanProperty
- Handle null in JPQL query
- Is there any way to combine several select statements into single query?
- Spring JPA query null check condition is removing all rows with null values
- spring boot 3 - hibernate 6.1 - group by error with constructor expression query
- How can i add "where" to my request to db from java in JPQL?
- Unable to instantiate class with Spring Data JPA projection in ManyToMany relationship
- join-fetch associated entity by default
- I have written the follwoing jpql query which is inserting a cross join between my entities. How do I avoid that?
- JPA JPQL select where one element in param list matches entity list
- JPA not generating queries correctly
- JPA select master and filter details by the master's property
- NamedBasicTypeImpl EntityValuedModelPart are in unnamed module of loader 'app'
Related Questions in TEMPORAL
- What spatial-temporal analysis technique should I use to find the spatial-temporal overlap of two point datasets?
- Concurrent Execution of Workflow and Activities in One Worker Instance
- Incorporating time into shortest path calculations in R {igraph} or similar packages
- How to Integrate Temporal Workflow into Clean Architecture for Go Application?
- Temporal Workflow Issue in python: Workflow is not running in background, Unable to Trigger New Workflow Unit Until Current One Finishes
- Am I able to export ArcGIS Pro temporal data into one table of duplicates?
- Unity ShaderGraph Temporal Blur
- Unable to start Temporal Workflow in PHP
- How to load related data (e.g. Includes) for EFCore's TemporalAll?
- How to set up A3TGCN2 module using batches?
- Bean cannot be found unless it is in upper package
- ArcGIS Pro table field calculation: SUM of field where multiple attributes have same value
- Temporalis library in brightway2.5 AttributeError: 'NoneType' object has no attribute 'get'
- Temporal : Query on Promise with get() method call
- How to carry out population-mean cosinor analysis in R using 'card' package
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
JPA does not provide any standard date/time functions. You can use a native SQL query using SQL EXTRACT,
Or, if you are using EclipseLink you can use the FUNC JPQL operator to call a database specific function, or use EXTRACT if using EclipseLink 2.4,
See,
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#Functions