Spring jpa No converter found capable of converting from type AbstractJpaQuery$TupleConverter$TupleBackedMap [duplicate]

klh5stk1  于 2023-10-19  发布在  Spring
关注(0)|答案(1)|浏览(126)

此问题已在此处有答案

Spring JPA native query with Projection gives "ConverterNotFoundException"(5个答案)
上个月关门了。
我的实体:

@Entity(name = "Car")
@Table(name = "Car")
@Builder
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class CarEntity
{
   private final String identification;
   private final String attribute_2;
   private final String attribute_3;
   private final String attribute_4;
   private final String attribute_5;
   private final String attribute_6;
}

Dto还有两个属性。
我的DTO:

@RequiredArgsConstructor
@Builder
@Getter
@Setter
public class CarDto
{
   private final String identification;
   private final String attribute_2;
   private final String attribute_3;
   private final String attribute_4;
   private final String attribute_5;
   private final String attribute_6;
   private final String childCarIdentification;
   private final String parentCarIdentification;
}
@Entity(name = "CarRelation")
@Table(name = "CarRelation")
@IdClass(CarRelationId.class)
@Builder
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class CarRelationEntity
{
   @Id
   private String carIdentification;
   @Id
   private String subCarIdentification;
}

CarRelationId

@Builder
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class CarRelationId implements Serializable
{
   private String carIdentification;
   private String subCarIdentification;
}

Carpet Dto:

@RequiredArgsConstructor
@Builder
@Getter
@Setter
public class CarRelation
{
   private final String carIdentification;
   private final String subCarIdentification;
}

我的存储库:

@Repository
public interface JpaCarRepository extends JpaRepository<CarEntity, String>
{
   @Query("""
         SELECT        c.identification, c.attribute_2, c.attribute_3, c.attribute_4,
            c.attribute_5, c.attribute_6, cr.subCarIdentification AS childCarIdentification, cr_1.carIdentification AS parentCarIdentification
         FROM            Car c LEFT OUTER JOIN
                                  CarRelation cr ON cr.carIdentification = c.identification LEFT OUTER JOIN
                                  CarRelation AS cr_1 ON c.identification = cr_1.subComponentIdentification
         WHERE        (c.identification = :identification )
    """)
   Optional<CarDto> findByIdentification(@Param("identification ") String identification );

错误:

No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [path.to.object.Car]

如何将Sql-Result转换为CarDto对象,以及如何将结果传递给Dto对象

相关问题