Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring DATA JPA Between and IsBetween keywords

Tags:

How to get Spring DATA JPA method (like findBy....) for the query below:

Select * from USER where '2016-02-15' between VALID_FROM and VALID_TO; 
like image 222
Mayank Porwal Avatar asked Feb 10 '16 15:02

Mayank Porwal


People also ask

What is the difference between JPA and Spring data JPA?

As we saw above, JPA is a standard for defining the persistence layer and Spring Data JPA is a sub-project under the Spring Framework umbrella which allows Spring applications to integrate with JPA.

What is the difference between Spring data JPA and Hibernate?

What Is the Difference Between Hibernate and Spring Data JPA? Hibernate is a JPA implementation, while Spring Data JPA is a JPA Data Access Abstraction. Spring Data offers a solution to GenericDao custom implementations. It can also generate JPA queries on your behalf through method name conventions.

What is the difference between save and saveAndFlush in JPA?

Save and saveAndFlush both can be used for saving entities. They both are both belong to the Spring data library. save may or may not write your changes to the DB straight away. When we call saveAndFlush system are enforcing the synchronization of your model state with the DB.

What is difference between JpaRepository and PagingAndSortingRepository?

PagingAndSortingRepository provides methods to do pagination and sort records. JpaRepository provides JPA related methods such as flushing the persistence context and delete records in a batch.


1 Answers

You should do it in this way

SELECT * FROM users u WHERE e.REFERENCE_FIELD BETWEEN startDate AND endDate 

Your code is not very clear, and I dont know what is 2016-02-15, if is the name of your field or is a value, if is a value and you are using between, you must specify a range, and a field to be compared.

EDIT

If you want to use spring data jpa then do it like this

findReferenceFieldBetween(value1,value2); 

check the ref. here

like image 51
jpganz18 Avatar answered Oct 13 '22 23:10

jpganz18