findAllVIPS (); I have this method in repository class, " /> findAllVIPS (); I have this method in repository class, " /> findAllVIPS (); I have this method in repository class, "/>

Unable to map data from JPA query to model class

19 views Asked by At
 @Query(value = "SELECT DISTINCT vip, instance FROM REPORT", nativeQuery = true)
    List<VipINFO> findAllVIPS ();

I have this method in repository class, I want to map this data to List.

public class VIPInfo
{
    private String vip;

    private String instance;
}

I am getting this error when calling findAllVIPS method.

No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.sap.ariba.security.emc.model.HanaVIPInfo]

1

There are 1 answers

0
phuongnq1995 On

You can’t rely on Spring Data JPA’s automatic mapping feature when using a native query

The easiest way to do it is using interface-based DTO.

public interface VIPInfo {
    String getVip();
    String getInstance();
}

If you still want to use class-based DTO then you must define and reference a @NamedNativeQuery with an @SqlResultSetMapping.

Refer to this article