1

Trying to find a way around an integer being replaced with "?".

SQL that works as expected:

select max(m.ticket_num) **+ 1** from mytable m where current date = DATE(m.create_ts)

JPQL:

@NamedQuery(
      name = "Orders.findNewTicketNum", 
      query = "SELECT max(M.ticketNum) **+ 1** FROM Mytable m WHERE CURRENT_DATE = FUNCTION('DATE',m.createTs)")

Printing out the query before execution shows:

EJBQueryImpl(
        ReportQuery(
         name="Mytable.findNewTicketNum" 
         referenceClass=Mytable 
         sql="SELECT (MAX(TICKET_NUM) **+ ?**) FROM MYTABLE WHERE (CURRENT_DATE = DATE(CREATE_TS))"))

The "+ 1" is changed to "+ ?" and the application hangs on the initial run of the query. I can get around this by adding 1 in code, but I would like to know if I am missing something. I looks like "1" is being parse as an indexed placeholder and I thought the syntax was: "?1".

I looked at escaping the "1", but I think that only applies to "like" clauses. ... + \1 ... the result was that the "1" was removed in the final sql.

I also tried using a named parameter of type Integer, but that was also replaced with "?".

Is there a way to add a constant value in JPQL?

codingadventures
  • 2,924
  • 2
  • 19
  • 36
DanielGA
  • 11
  • 3
  • JPQL doesn't replace anything with anything. Your JPA implementation may well do, but we don't see which one it is. The one I use doesn't do that (note: I assume that the asterisks are not actually in the JPQL/SQL and are there to highlight something) – Neil Stockton Apr 29 '15 at 05:56

0 Answers0