I am getting the following exception:
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value did not match expected type. [java.util.Date (n/a)];
nested exception is java.lang.IllegalArgumentException: Parameter value did not match expected type [java.util.Date (n/a)]
Here is my query method in my repository:
@Query("SELECT COUNT(entity) FROM Person entity WHERE trunc(entity.date) BETWEEN :startTime AND :endTime")
int getPersonBetweenDates(@Param("startTime") DateTime var1, @Param("endTime") DateTime var2);
And my implementation in component:
int totalPersons = personRepo.getPersonBetweenDates(new DateTime().withTimeAtStartOfDay(), DateTime.now());
Why am I getting this error? It seems that the two DateTime parameters in the implementation match those in my method?
Parameter value did not match expected type. [java.util.Date (n/a)];
Instead of using joda's DateTime
in method parameters, use java.util.Date
, Like following:
@Query("SELECT COUNT(entity) FROM Person entity WHERE trunc(entity.date) BETWEEN :startTime AND :endTime")
int getPersonBetweenDates(@Param("startTime") Date var1, @Param("endTime") Date var2);
Then in your client code, if you have some DateTime
instances, you can use toDate
method to convert the DateTime
into a Date
:
personRepo.getPersonBetweenDates(new DateTime().withTimeAtStartOfDay().toDate(), DateTime.now().toDate());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With