2

I have a native query inside a JPA repository :

public interface TaskRepository extends PagingAndSortingRepository<Task, Integer> {
    @Query( nativeQuery = true, value = "select min(t_id) as id, sum(t_estimation_time) as estimationTime, max(t_due_date) as maxDueDate, min(t_due_date) as minDueDate  "
                + "from kat_task inner join kat_task_to_workstream on t_id = ttw_frn_task_id "
                + "inner join kat_workstream on ws_id = ttw_frn_workstream_id and t_is_active is true and t_completed_at is null and t_is_active is true "
                + "where ws_id= :workstreamId" )
        DueDatesAndEstimationTimeBean getDueDatesAndEstimationTime( @Param( "workstreamId" ) Integer workstreamId );

    }

But, when I run the above query I am getting exception

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [com.kat.beans.DueDatesAndEstimationTimeBean] for value '{15666, 10800000, 2017-04-27 14:21:16.0, 2017-03-13 12:20:33.0}'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [com.kat.beans.DueDatesAndEstimationTimeBean].

Why it is failing to convert? I am new to spring data JPA. Please help

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Virat
  • 551
  • 4
  • 9
  • 23
  • format your code. this way it is impossible to read – pvpkiran May 09 '17 at 16:15
  • What does the DueDatesAndEstimationTimeBean look like and how does it relate to Task? Edit: oh wait, you got the generics wrong, too. It's entity and id, right? – rob May 09 '17 at 17:03
  • @rob Ya they are the entity and Id. But can't I map to other POJO than the entity? – Virat May 09 '17 at 17:33
  • 2
    Are you required to write a native query? with JPQL you can use `SELECT new DueDateAndEstimationTimeBean( MIN(t.id) AS id, SUM(t.estimationTime), ) FROM KatTast t .` – Jason White May 09 '17 at 22:09
  • 2
    here is a similar question http://stackoverflow.com/questions/29082749/spring-data-jpa-map-the-result-to-non-entity-pojo – Jason White May 09 '17 at 22:30

0 Answers0