当前位置: 首页 > 知识库问答 >
问题:

错误:找不到能够从类型JPA模型类型转换为自定义对象[Model]的转换器

田兴怀
2023-03-14
  1. 这是我的pojo课程
public class Payload {

private Clob paylaod;


public Clob getPaylaod() {
    return paylaod;
}

public void setPaylaod(Clob paylaod) {
    this.paylaod = paylaod;
}

}
@Entity
@Table(name ="ORDER")
@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Model implements Serializable {
    
        @Id
        @Column(name = "REQUEST_ID", nullable = false, unique = true)
        private String requestId;

        @Column(name = "VERSION")
        private BigDecimal version;

        @Column(name = "SOURCE")
        private String source;

        @Column(name = "SOURCE_ID")
        private String sourceId;
        
        @Lob
        @Column(name = "PAYLOAD")
        private Clob  payload;
}

3.这是我的存储库。

public interface OrderRepository extends JpaRepository<Model, String>
{
    
    @Query(value="SELECT PAYLOAD FROM ORDER WHERE REQUEST_ID = ?",nativeQuery = true)
    Payload getDetailsById(String requestId);
}
@RestController
@RequestMapping("/v1/order-data/Order")
public class OrderController {
    
    @Autowired
    OrderRepository repository;
    
    
    @GetMapping("/getDetailsById/{requestId}")
    public Payload getDetailsById(@PathVariable("requestId") String id) {
        return  repository.getDetailsById(id);
    }
    
}

4.获取以下错误:

共有2个答案

齐文栋
2023-03-14

我认为getDetailsById()方法的返回类型是Payload而不是Clob,请更改它并尝试运行。这可能有用。

谢海阳
2023-03-14

尝试将PAYLOAD值直接存储到Clob中,而不是将其存储到pojo类中。

public interface OrderRepository extends JpaRepository<Model, String>
{
    
    @Query(value="SELECT PAYLOAD FROM ORDER WHERE REQUEST_ID = ?1",nativeQuery = true)
    Clob getDetailsById(String requestId);
}

试着使用?1用于编写参数化查询。

 类似资料: