简体   繁体   中英

JPA and Postgres generate_series

I have problem with JPA. I start with something like that (I have reduced the query to a fragment that causes an error):

entityManager.createNativeQuery("select * from generate_series(:from::date, :to, '1 day') as dt").setParameter("from", from).setParameter("to", to).getResultList();

and have "Not all named parameters have been set" error. I found that I should change it to something like that:

entityManager.createNativeQuery("select * from generate_series (date :from, :to, '1 day') as dt")...

or

entityManager.createNativeQuery("select * from generate_series (cast (:from as date), :to, '1 day') as dt")...

I tried also positional parameters:

entityManager.createNativeQuery("select * from generate_series (cast (?1 as date), ?2, '1 day') as dt")...

Unfortunately, it did not help. I would ask for some suggestions on how you can solve this problem. I use Hibernate.

I'm sorry for the lack of response. I change to positional parameters and date to timestamp, my ide (IntelliJ IDEA) still shows an error "Cannot resolve query parameter" but when i deploy it on server its work.

entityManager.createNativeQuery("select * from generate_series(cast (?1 as TIMESTAMP), cast(?2 as TIMESTAMP), '1 day'").setParameter(1, from).setParameter(2, to).getResultList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM