Skip to content
Advertisement

Unknown data type when using an integer over NamedParameterJDBCTemplate on H2 [SPRING-BOOT]

I’m testing a Dao with an In-Memory DB with H2. I’m passing an int to the query with a map to execute it. This query is working OK on Oracle SQL, but is not succeding in H2.

DAO

JavaScript

QUERIES

JavaScript

When I try to execute this query on H2, it returns:

Error

JavaScript

I tried to execute the query hardcoding the int in the query (SYSDATE = 4) and it worked, also tried to wrap primitive int into Integer.valueOf(days) and using MapSqlParameterSource to specify which data type is, but none of both worked.

Why is it not working? Anyone knows? Thanks in advance.

EDIT:

StatusEnum

JavaScript

}

Advertisement

Answer

This exception appears to arise because H2 is trying to type-check the statement at compile time and can’t uniquely determine the type of the parameter: it could be a date or it could be a number, or perhaps something else.

The workaround (provided in the GitHub issue I raised) is to replace

JavaScript

with

JavaScript

I’ve checked this and it works on both H2 and Oracle.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement