Nazerke
Nazerke

Reputation: 2098

Java query for postgresql's interval method not working

I'm writing postgresql query. When I run the query

"reservatio0_.DATE_ >(NOW() - '60 MINUTES'::INTERVAL)" on pgAdmin it works fine, but in java I get

QuerySyntaxException, unexpected token: : bla bla

if I run this code

List<Reservation> list = em.createQuery( 
                                    "select r " +
                                    "from Reservation r " +
                                    "where r.group.id=:groupName " +
                                 "  and  r.date >(NOW() - '60 MINUTES'::INTERVAL) " +
                                    "order by r.date asc")
                                    .setParameter("groupName", groupName)
                                    .setParameter("number", number)
                                    .setMaxResults(1)
                                    .getResultList();

Upvotes: 0

Views: 1380

Answers (2)

Angelo Fuchs
Angelo Fuchs

Reputation: 9941

IIrc you have to put the interval in front of the amount, like this:

and  r.date >(NOW() - interval '60 minutes')

Upvotes: 0

try to replace your colon operator (:) with \\:
that would escape this special character..

Upvotes: 2

Related Questions