0
I want to return the value of playlists
at the bank, but that code there 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();
}
}
tries to change from "int" to "Long" on the return of your method.
– Adriano Gomes
@Adrianogomes How would that help? A
int
goes up to2.147.483.647
, right?– Jéf Bueno
Henrique, please specify what you mean by "this code didn’t work". Doesn’t it compile? Error returns? Zero returns? Returns a number nothing to do with the expected?
– Jéf Bueno
@LINQ The return of Count in Hibernate is a Long and not an integer, so I believe that Spring jpa behaves the same way.
– Adriano Gomes
@Adrianogomes Now it makes sense =D
– Jéf Bueno
I switched to Long, and tested:public Static void main(String[] args) { Playlistserviceimpl se=new Playlistserviceimpl(); System.out.println(se.verifies(); }
– Henrique Santos
Gives a java.lang.Nullpointerexception
– Henrique Santos
Your test is wrong. You can’t use
new PlaylistServiceImpl()
, this way dependency injections are not made. Read this article to better understand: Injection of Dependencies with Spring– eugenioflima
Try
@Query("select count(p) from Playlist p")
and let me know if it works.– StatelessDev
Gave Nullpointerexception , I have to know the type of return I put
– Henrique Santos