How to query distinct years from date fields using Spring JPA and QueryDSL?
I'm new to Spring Data JPA and I've got a JPA Entity with a created_on date field. Is there someway I can create a JPA query using QueryDSL to get a distinct set of years?
In standard SQL, the query would look something like:
Code:
SELECT DISTINCT YEAR(created_on) FROM table
but I'm having trouble understanding how to create this query with SpringData & QueryDSL. Do I have to create a custom repo which injects the EntityManager and create a query from that? I thought that using SpringData & QueryDSL would abstract the need to use the EntityManager, but the only way I can figure this would imply/indicate that it can't.
And even with the EM, I'm not entirely sure how to properly to implement the query.
Can anyone provide some advice and/or example?
Thanks!
Eric