Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query by Boolean properties in spring-data-jpa without using method parameters

Is it possible to query by Boolean properties in Spring Data JPA without using method parameters?

Basically I would like this to work without using custom @Query annotation:

@Query("SELECT c FROM Entity c WHERE c.enabled = true")
public Iterable<Entity> findAllEnabled();
like image 556
Mike Minicki Avatar asked Jul 11 '13 18:07

Mike Minicki


2 Answers

The JPA repository section query creation has the following methods.

True    findByActiveTrue()  … where x.active = true
False   findByActiveFalse() … where x.active = false

My guess would be to use

@Query
public Iterable<Entity> findByEnabledTrue();
like image 158
orangegoat Avatar answered Nov 09 '22 01:11

orangegoat


The @Query anotation can even be skipped. So it should just work just like this:

public Iterable<Entity> findByEnabledTrue();
like image 39
megalucio Avatar answered Nov 09 '22 03:11

megalucio