DateAdd function is working fine as a sql query in sql-server as i want to substract some number of days from a date and i am getting result but while same i am using in jpa project, spring boot project has not started.
Below the repository class, if i comment out this below line of code, spring boot project starts as expected.
public interface domainRepository extends CrudRepository<domainTable , Long> {
@Query("Select DATEADD(day,-(1), d.date) from domainTable d "
+ "where d.id in (:id)")
public Date getDate(@Param("id") Long id);
}
How to fix this? or i do have to write a separate function instead of DATEADD?
Actually, JPA doesn't support time periods operations because not all databases support it. So you have following options:
1- Calculate date programmatically (Java side, using calendar API or Java 8 Date Time API).
2- Use native query.
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