找不到能够从[org.springframework.data.jpa.repository.query.AbstractJpaQuery $ TupleConverter $ TupleBackedMap类型转换的转换器

时间:2018-11-06 17:17:30

标签: java hibernate jpa spring-data-jpa

将实体的结果集映射到POJO时出现问题。

实体使用来自元组的休眠结果集映射,并且应将带注释的值传递到POJO的构造函数中。

实体

@SqlResultSetMapping(
        name = "TaskChangeMapping",
        columns = {
                @ColumnResult(name = "id", type = Long.class),
                @ColumnResult(name = "status", type = String.class),
                @ColumnResult(name = "data_values", type = String.class)

})
@NamedNativeQueries({
    @NamedNativeQuery(
      name = "ICreateChange.listStartedChangesByInitiator",
      query =
      "SELECT id, status, data_values "
      + "FROM icreate_change "
      + "WHERE initiator = :initiator "
      + "AND workflow_process_id = 0",
      resultSetMapping = "TaskChangeMapping"
    ),
    @NamedNativeQuery(
      name = "ICreateChange.listDataValuesAndStatusByChangeId",
      query =
      "SELECT id, status, data_values "
      + "FROM icreate_change "
      + "WHERE id = :changeId",
      resultSetMapping = "TaskChangeMapping"
    )
})

@Data
@Entity
@Table(name = "icreate_change")
public class ICreateChange {
...

这是POJO类

ChangeTask

@Data
public class ChangeTask {

  @Getter
  @Value("id")
  private Long id;

  @Getter
  @Value("status")
  private String status;

  @Getter
  @Value("data_values")
  @JsonInclude(Include.NON_NULL)
  private String dataValues;

  /**
   * Constructor.
   * @param id changeId
   * @param status change status
   * @param dataValues JSON string of data values
   */
  public ChangeTask(
      Long id,
      String status,
      String dataValues
  ) {
    this.id = id;
    this.status = status;
    this.dataValues = dataValues;
  }
}

存储库

请注意,没有休息控制器,它直接到存储库

@CrossOrigin
@RepositoryRestResource(path = "/iCreateChange")
public interface ICreateChangeRepository extends JpaRepository<ICreateChange, Long> {

  List<ChangeTask> listDataValuesAndStatusByChangeId(
        @Param("changeId")
        @RequestParam
        @ApiParam(name = "changeId", value = "changeId")
        Long changeId);
}

调用listDataValuesAndStatusByChangeId时,将发生以下堆栈跟踪

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.jlr.ddc.cmpdataapi.model.ChangeTask]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
    at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:293) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.lambda$and$0(ResultProcessor.java:213) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.query.ResultProcessor$ChainingConverter.convert(ResultProcessor.java:224) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:152) ~[spring-data-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:141) ~[spring-data-jpa-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125) ~[spring-data-jpa-2.1.2.RELEASE.jar:2.1.2.RELEASE]

有什么想法吗?

0 个答案:

没有答案