how to get a value from a repository with a value which is compared with two fields of a table

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.?

Answers


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);
}

Need Your Help

What's the default of ONDELETE and ONUPDATE for foreign keys in SQL?

sql foreign-keys constraints

My guess would be that a foreign key reference is set to RESTRICT by default. But, is there any standard for this? Is the default equal on any database type? Or should these values be defined in all