4

I want to use following mysql function in JPQL:-

TIMESTAMPDIFF(YEAR, some_start_date, CURDATE());

Also, I do not have to use Criteria in JPA, since we are following practice of writing Named queries(JPQL). So, how can this function be written in JPQL?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Sumit Desai
  • 1,542
  • 9
  • 22

2 Answers2

1

There is no timestampdiff in JPQL. Eclipse has keyword FUNC which allows to call DB-specific functions, like timestampdiff.

asm0dey
  • 2,841
  • 2
  • 20
  • 33
1

If you are using JPA 2.1 or later version, try the following JPQL:

select a from EntityClass a where FUNCTION('DATEDIFF', CURRENT_DATE, a.createDt) / 365 >= 1

The above JPQL is to retrieve all entities which have been created for more than 1 year.

Dicky Ho
  • 35
  • 6