Resolved [org.springframework.orm.jpa.JpaSystemException: attempted to assign id from null one-to-one property [com.example.bootapp.entity.Employee.user]; nested exception is org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [com.example.bootapp.entity.Employee.user]]用户实体
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "id")
@JsonIgnore
@Getter @Setter
private Employee employee;雇员实体
@OneToOne(fetch = FetchType.LAZY)
@MapsId
@JsonIgnore
private User user;提前感谢!
发布于 2020-02-29 10:25:45
解决了!
user.setEmployee(null); // I added this line
userCommandService.save(user);
employee.setUser(user);
employeeCommandService.save(employee);通过将用户实体中的employee设置为null,我的错误消失了!
https://stackoverflow.com/questions/60463902
复制相似问题