I'm developping a Java Spring API and i have an issue with JPQL. I wanna get a boolean value but i get Null.
@Query("
SELECT
CASE WHEN TRIM(m.mobile) = TRIM(:mobile)
THEN true ELSE false
END
FROM #{#entityName} m"
)
Boolean findMemberByMobile(String mobile);
// result: null
// springboot: 2.7.3, SGBDR: PostgreSQL
Helps please and thanks
CodePudding user response:
Would be helpful if you include the code of your whole repository class, but here's what I found helpful that might help you as well: FYI, it is using Spring Data JPA Query.
@Repository
public interface CompanyRepository extends JpaRepository<Company, Integer> {
@Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM Company c WHERE c.name = :companyName")
boolean existsByName(@Param("companyName") String companyName);
}