I implemented a repository, an entity and a POJO where I want to call the findAll() method from the repository, but it returns null pointer exception, even though I have the database populated. The problem is that the repo is null, not the list after executing the select. Can anyone help me?
This is my repo:
@Repository
public interface UpcomingMatchesFactsRepository extends
CrudRepository<UpcomingMatchesFacts, Integer> {
public boolean existsByFirstPlayerName(String firstPlayerName);
@Query(value = "" +
"Select u " +
"from UpcomingMatchesFacts u " +
"order by abs(formula) desc ")
List<UpcomingMatchesFacts> getHighestFormulaMatches();
List<UpcomingMatchesFacts> findAll();
}
This is my Entity:
@Entity
@Table(name = "upcomingmatchesfacts")
public class UpcomingMatchesFacts {
public UpcomingMatchesFacts(String firstPlayerName, String secondPlayerName, int matchesWonFirstPlayer,
int matchesWonSecondPlayer, int currentRankFirstPlayer, int currentRankSecondPlayer,
int ageFirstPlayer, int ageSecondPlayer, double formula) {
this.firstPlayerName = firstPlayerName;
this.secondPlayerName = secondPlayerName;
this.matchesWonFirstPlayer = matchesWonFirstPlayer;
this.matchesWonSecondPlayer = matchesWonSecondPlayer;
this.currentRankFirstPlayer = currentRankFirstPlayer;
this.currentRankSecondPlayer = currentRankSecondPlayer;
this.ageFirstPlayer = ageFirstPlayer;
this.ageSecondPlayer = ageSecondPlayer;
this.formula = formula;
}
And this is the class where I want to use the method:
@EnableJpaRepositories
public class ChooseBestMatches {
@Autowired
private UpcomingMatchesFactsRepository upcomingMatchesFactsRepository;
public void addBestMatchesToDatabase() {
List<UpcomingMatchesFacts> upcomingMatchesFacts = Lists.newArrayList(upcomingMatchesFactsRepository.findAll());
//upcomingMatchesFactsRepository.getHighestFormulaMatches().subList(0, 9);
}
}