Java : 实体类不能序列化异常
当修改实体类之后调用接口出现不能序列化的异常时,一定要检查实体之间的关系是否都是正确的.
could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize
原因
// 学生字段
@Column(name = "user")
private User user;
发送请求会出错 500 "could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize 序列化失败
// 学生字段
@JoinColumn(name = "user")
private User user;
发送请求会出错 500 "could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize 序列化失败
// 学生字段
@ManyToOne
private User user;
成功 表中添加user_id字段 joinColumn 可以省略
// 学生字段
@ManyToOne
@Column(name = "user")
private User user;
用Column启动报错
结论,存在一对多多对一多对多关系时必须使用注解否则会序列化失败 joincolumn只是改变字段名