JPA: How do I add new Items to a List with a OneToMany annotation

微笑、不失礼 提交于 2019-12-04 12:59:53

I think the issue may be in your join column annotation in the Phone class. You are specifying a join column of employee_id yet in the Employee class the @Column annotation for the id field is mapped to the column id.

Try changing/synchronizing the join columns:

@ManyToOne(fetch = FetchType.EAGER, targetEntity=your.package.here.Employee.class)
@JoinColumn(name = "id")
private Employee owner;

or

Employee.java

@Id
@Column(name = "employee_id", unique = true, nullable = false)
@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
private Integer id;

Phone.java

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "employee_id", targetEntity=your.package.here.Employee.class)
private Employee owner;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!