java – What return type of a select count(*) in Spring JPA?


I need to know the type of return that Spring JPA returns to put in the Service package, as it is giving a NullPointerException :


public interface PlaylistDao extends JpaRepository<Playlist, Long> {
    @Query("select count(*) from Playlist")
    public int verifica();


public class PlaylistServiceImpl implements PlaylistService {

    private PlaylistDao dao;

    public int verifica(){
        return dao.verifica();


The JpaRepository interface (which inherits from CrudRepository ) already comes with a ready-made method for this action.
It's called count() and returns a long .

Instead of declaring a new method, you can use this one.

See the documentation for more information.

Scroll to Top