Return Boolean in SELECT

1

I have an entity called "Period" with a boolean attribute called "processing". I want to make a function for a repository that returns "true" if there is at least one record in the DB with the attribute "processing in true", however I'm not sure how to do it with Jpa, this is what I tried:

public interface PeriodoRepository extends JpaRepository<Periodo, Long> 
{

    @Query("SELECT CASE WHEN EXISTS ( SELECT P FROM Periodo P WHERE 
    P.procesando = false ) THEN CAST(0 AS BIT) ELSE CAST(1 AS BIT) END")
    public boolean isPeriodoProcesando();
}
    
asked by gibran alexis moreno zuñiga 12.06.2017 в 18:40
source

1 answer

0

You could return a Boolean instead of a Bit

public interface PeriodoRepository extends JpaRepository<Periodo, Long> 
{
    @Query("SELECT CASE WHEN EXISTS ( SELECT P FROM Periodo P WHERE 
    P.procesando = false ) THEN FALSE ELSE TRUE 
    END")
    public boolean isPeriodoProcesando();
}
    
answered by 14.06.2017 в 02:06