Erro在坚持该实体,如何解决?

时间:2019-05-14 15:12:07

标签: jpa

我想保留实体Meet,我想保留Meet表,但是我不知道为什么我不能推理,错误是联接? 当我正确编译所有内容时,在创建聚会时就会发生错误。

@Entity
@Table(name = "Meet")
public class Meet {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Column(unique = true, name = "name")
    private String name;

    @Column(name = "state")
    private State state;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "id_bet", referencedColumnName = "id")
    private Bet bet;

    @OneToMany(fetch = FetchType.EAGER)//, mappedBy="meet"
    @Column(name = "users")
    @JsonBackReference
    private Set<User> users = new HashSet<>();

这是类User:

@Entity
@Table(name = "User")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

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

    @Column(name = "password")
    private String password;

    @Column(unique = true, name = "email")
    private String email;

    @Column(name="rol")
    Rol rol;

//    @ManyToOne
//    @JoinColumn(name="user")
//    @JsonManagedReference
//    Meet meet;

    @Column(name = "life")
    Life life;

这是我用来测试createMeet函数端点的控制器

 @PostMapping("/createMeet")
    public ResponseEntity<Meet> createMeet(@RequestParam("user") Long idUser,@RequestBody Meet meet ) {
        return new ResponseEntity<Meet>(meetService.createMeet(idUser, meet), HttpStatus.OK);
    }

这是我运行createMeet函数时遇到的错误:

2019-05-14 10:59:38.583  INFO 7236 --- [io-8080-exec-10] c.e.demo.controller.UserController       : CREATE
Hibernate: select user0_.id as id1_5_, user0_.email as email2_5_, user0_.life as life3_5_, user0_.name as name4_5_, user0_.password as password5_5_, user0_.rol as rol6_5_ from user user0_ w
here user0_.email=?
Hibernate: select user0_.id as id1_5_, user0_.email as email2_5_, user0_.life as life3_5_, user0_.name as name4_5_, user0_.password as password5_5_, user0_.rol as rol6_5_ from user user0_ w
here user0_.id=?
Hibernate: select user0_.id as id1_5_0_, user0_.email as email2_5_0_, user0_.life as life3_5_0_, user0_.name as name4_5_0_, user0_.password as password5_5_0_, user0_.rol as rol6_5_0_ from u
ser user0_ where user0_.id=?
2019-05-14 11:00:27.840  WARN 7236 --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableExc
eption: JSON parse error: Can not deserialize instance of com.example.demo.model.User out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can
not deserialize instance of com.example.demo.model.User out of START_ARRAY token
 at [Source: java.io.PushbackInputStream@1f590a2b; line: 9, column: 12] (through reference chain: com.example.demo.model.Meet["users"])

0 个答案:

没有答案