Spring DATA JPA how to write a method which use contant value for a field to fetch data

Viewed 3912

Hi I am using Spring Data JPA and want to use feature generate query from method name. I have a field active in DB which have only value 0 and 1. I want to fetch all data with which have active value is 1. This is a constant value so i don't want to pass this value as method arguments.

please suggest what will be the method for the same.

example:

I have a entity EmailRef

public class EmailRef {

    /* other vareialbe */

    @Column(name="is_active") /* this is the field which value is 0 and 1 in DB*/
    private Integer active;

    /* setter getter method */       
}

This is the repository for where I want to write method which will fetch all data for which active is 1;

public interface EmailRefRepositry extends JpaRepository<EmailRef, Long> {          

    @Query("select * from email_reference where is_active=1") /* this is the query I want to convert into method*/
    List<EmailRef> findByActive(); /*I want to write method like that which will fetch all data form table where active field value is 1*/
}

I am stuck for constant vale please suggest

Thanks Sudhanshu

3 Answers
Related