0

My Entity:

@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;
}

The Dto has two attributes more.

My 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;
}

The CarRelationId:

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

The CarRelationDto:

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

My repository:

@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 );

The error:

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

How can i transform the Sql-Result to CarDto Object other how the pass the Result to a Dto Object

emoleumassi
  • 4,881
  • 13
  • 67
  • 93

1 Answers1

0

Use @SqlResultSetMapping as explained here

Mircea Sirghi
  • 310
  • 1
  • 6