Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Framework JpaRepository returns duplicates of first table row by findAll() method

Here is my JpaRepository

public interface ProcessorRepository extends JpaRepository<Processor, Integer> {
}

Controller

...
@Autowired
ProcessorRepository processorRepository;

@RequestMapping("/getAll")
public String showAllProcessors(Map map){

    List<Processor> processorList = processorRepository.findAll();

    map.put("processors", processorList);
    return "main";
}

main.jsp

....
<select>
<option selected="selected">Choose Processor</option>
<c:forEach var="proc" items="${processors}">
    <option>
            ${proc.processorName}
    </option>
</c:forEach>
</select>

This is how Processor mysql table looks like:

Processor table


But this is what I get

enter image description here

Why it returns duplicates of first row, instead of all different rows?

like image 831
Kolos Avatar asked Sep 15 '25 10:09

Kolos


1 Answers

Turned out the problem was in my Processor entity. It had @Column(name="id") instead of @Column(name="processor_id").

like image 177
Kolos Avatar answered Sep 18 '25 05:09

Kolos