0

I want to create a query with JPA using dates. I´ve created this query with Oracle

 "SELECT * FROM PMAR_PRON WHERE to_char(PRO_DATE,'mm')=10 and 
to_char(PRO_DATE,'YYYY') = 2015;" 

it works well but i don´t know how to convert it at JPA.

SELECT * FROM PMAR_PRON WHERE to_char(PRO_DATE,'mm')=10 and 
to_char(PRO_DATE,'YYYY') = 2015;"

I want to get records of month 10 and year 2015.

Stedy
  • 7,359
  • 14
  • 57
  • 77
  • 1
    Have a look [here](https://stackoverflow.com/questions/3674567/jpa-query-month-year-functions) for some options. JPA does not have particularly good native date function support. The main reason for this is that date implementation on various databases can be so different. – Tim Biegeleisen Apr 08 '19 at 14:50
  • I tried but did not work. says that function MONTH is invalid – anibal sibrian Apr 08 '19 at 15:15
  • Thank you to everyone. I solved it using NativeQuery – anibal sibrian Apr 25 '19 at 15:15

1 Answers1

0

You can do:

TypedQuery<MyObject>  query = em.createQuery("SELECT    * FROM PMAR_PRON WHERE to_char(PRO_DATE,'mm')=10 and to_char(PRO_DATE,'YYYY') =  :yr", MyObject.class);

query.setParameter("vr",year);
return query.getResultList();