How do I retune the amount of Spring JPA records? [duplicate]

0

I want to return the value of playlists records in the database, but that code did not work.

public interface PlaylistDao extends JpaRepository<Playlist, Long> {

    @Query("select count(*) from Playlist")
    public int verifica();
}

@Service
@Transactional
public class PlaylistServiceImpl implements PlaylistService {

    @Autowired
    private PlaylistDao dao;

    public int verifica(){
        return dao.verifica();
    }
}
    
asked by anonymous 20.11.2018 / 17:04

1 answer

0

This response is the same as the other similar question created by the same contributor. However, as it was not marked as duplicate yet, I responded here as well. I'm suggesting it as duplicate now.

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

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

See the documentation for more information. .

    
28.11.2018 / 18:49