Question

Hi i am new to spring JPA . I have a table which has two columns namely 'active_from' and 'active_to'.Now I would like to get a column which has a date(ie.current date) which has a value between "active_from" and "active_to".How to acheive this using spring jpa repositories.?

Était-ce utile?

La solution

This link you could find query methods to add queries that are not covered by the common jpa repository or with the support creation.

Check 2.3.4 Using @Query in JPA repositories

Using Query methods you can do that, try something like this.

public interface UserRepository extends JpaRepository<User, Long> {

  @Query(value = "SELECT * FROM USERS WHERE active_from > :?0 AND active_to < :?0 )
  List<User> findBetweenDate(String currentDate);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top