Ahkam Mohammed
Ahkam Mohammed

Reputation: 61

“ConverterNotFoundException” in Spring boot JPA

I want to get the SearchOutput data object by calling a query(@Query method) with natural joins of 3 tables. but when the query runs it shows an error.

I have tried to fetch the data in my spring boot controller class. But its not working because of the error

package com.example.mysqlproj.model;
import lombok.*;
public class SearchOutput {
    private String  hotel_name;
    private String room_type;
    private int price;

}

package com.example.mysqlproj.dao;
import com.example.mysqlproj.model.Room_Type;
import com.example.mysqlproj.model.SearchOutput;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public interface RoomTypeDao extends CrudRepository<Room_Type,Integer> {

    @Query(value="select new SearchOutput(hotel_name , room_type,(price*(?4)*(?3)*(1.15))) from Room_type natural join Hotel natural join True_contract where  (?1 >= start_date and ?2 <= end_date and ?3 <=available_rooms and ?4<= max_adults )", nativeQuery = true)
    List<SearchOutput[]> checkHotelList(Date from, Date to, int rooms, int adults, int total_nights);

}

The Error:

No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.example.mysqlproj.model.SearchOutput]] with root cause 

My target is to fetch a searchOutput object array when the query gets called. Are there any solutions for this. Thanks in advance

Upvotes: 1

Views: 861

Answers (1)

GnanaJeyam
GnanaJeyam

Reputation: 3170

The response type from the query is List<Map<String, Object>> .

Please change the method return type to this.

Upvotes: 1

Related Questions