Currently I am creating a Spring Boot application and getting this error
There was an unexpected error (type=Internal Server Error, status=500).Failed to convert from type [java.util.ArrayList<?>] to type [@org.springframework.data.jpa.repository.Query java.util.List<com.example.vismameetingappwithdb.entity.Meeting>] for value '[Jono Java Meetingas]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.data.jpa.repository.Query com.example.vismameetingappwithdb.entity.Meeting]
My repository interface looks like this:
@ Repository
public interface MeetingRepository extends JpaRepository<Meeting,Integer>{
@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
My RestController class looks like this:
@ RestController
public class MeetingController {
private MeetingService meetingService;
@ Autowired
public MeetingController(MeetingService meetingService){
this.meetingService = meetingService;
}
@ GetMapping("/getmeetings")
public List<Meeting> findAll (){
return meetingService.findAll();
}
@ GetMapping("/responsibleperson/{responsiblePerson}")
public List<Meeting> findAllByResponsiblePerson(@PathVariable String responsiblePerson) {
return meetingService.findAllByResponsiblePerson(responsiblePerson);
}
}
Has anyone encountered such problem before? Can anyone help? I am trying to use responsibleperson endpoint.
CodePudding user response:
Focus at your code
@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
- SQL query get list of
nameOfMeeting
, it isList<String>
. - Method returns list of
Meeting
, it isList<Meeting>
.
Thefore the mismatching causes error.