Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error in Spring Boot application failed to convert from one type to another

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@ 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.

>Solution :

Focus at your code

@ Query("SELECT nameOfMeeting FROM Meeting WHERE responsiblePerson =?1 ")
List<Meeting> findAllByResponsiblePerson(String responsiblePerson);
}
  • SQL query get list of nameOfMeeting, it is List<String>.
  • Method returns list of Meeting, it is List<Meeting>.

Thefore the mismatching causes error.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading