i use an EntityManager to create a nativeQuery. My database is a Postgres database. The date field i request is modelised like that..
@Column(name = "date", columnDefinition = "date", nullable = false)
private LocalDate date;
when i write this, all is fine..
String sqlRequest = "select insurer from stock where date='2021-01-01'";
Query query = entityManager.createNativeQuery(sqlRequest);
List<Object[]> records = query.getResultList();
but i when i wanna use the setParameter function..
String sqlRequest = "select insurer from stock where date=:param";
Query query = entityManager.createNativeQuery(sqlRequest);
query.setParameter("param", "2022-03-11");
List<Object[]> records = query.getResultList();
i got this issue..
No operator matches the given name and argument types. You might need to add explicit type casts.
any idea ?
CodePudding user response:
I think it's because you tried to set the param as String type instead of Date.
You should try to set LocalDate as time instead of "2022-03-11".