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

Mike Minicki picture Mike Minicki · Jul 11, 2013 · Viewed 65.8k times · Source

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

Answer

orangegoat picture orangegoat · Jul 11, 2013

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