【问题标题】:How to fix " TransientPropertyValueException" error in Spring Boot如何修复 Spring Boot 中的“TransientPropertyValueException”错误
【发布时间】:2019-04-09 06:38:52
【问题描述】:

我正在尝试使用 json 结构保存(POST),并且我需要使用外键(idClient 和 idUser),但它会产生所描述的错误,我不知道我是否正确发送它,idClient手动创建的,不是自动生成的。

并试图用注释解决它,但我做不到。

@JsonIgnore
    @OneToMany(mappedBy = "idClient", cascade = { CascadeType.PERSIST, CascadeType.MERGE,
            CascadeType.REMOVE}, fetch = FetchType.LAZY, orphanRemoval = true)
    private Collection<Pres> presCollection1;


@JsonIgnore
    @OneToMany(mappedBy = "idUser", cascade = { CascadeType.PERSIST, CascadeType.MERGE,
            CascadeType.REMOVE}, fetch = FetchType.LAZY, orphanRemoval = true)
    private Collection<Pres> presCollection2;



 @ManyToOne

    @JsonIgnoreProperties("id_client")
    @JoinColumn(name = "id_client",  referencedColumnName = "identi")
    private Person idClient;


    @ManyToOne

    @JsonIgnoreProperties("id_user")
    @JoinColumn(name = "id_user",  referencedColumnName = "identi")
    private Person idUser;



JSON TO SEND


{ 
    "date": "2019-03-24T05:00:00.000Z",
    "lastDate": "2019-09-24T05:00:00.000Z",
    "idClient":{"idClient":11},
    "idUser":{"idUser":12}

}

我需要保存客户端和用户 ID

【问题讨论】:

  • 显示完整堆栈以及保存的事务方法
  • @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntityregistrar(@Valid @RequestBody Perst prest){ Perst perst = service.save(prest); URI 位置 = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(emp.getIdPrest()).toUri(); return ResponseEntity.created(((URI) location).normalize()).build(); }

标签: json rest spring-boot


【解决方案1】:
cascade = {CascadeType.MERGE,
            CascadeType.REMOVE}

你必须合并这些值,所以只给级联类型合并。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-22
    • 2023-01-28
    • 2019-09-10
    • 2022-10-07
    • 1970-01-01
    • 2019-12-07
    • 2019-05-01
    相关资源
    最近更新 更多