mappedBy属性:one2many

    附一个one2many的例子 帮助理解mappedBy属性。
    例子中:
@Entity
public class Department {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int deptid;
private String dname;
private String location;
@OneToMany(mappedBy = "department")
private Set<User> users = new HashSet<User>();

所以department 表中只有deptid、dname、location三个字段,而users 则交给User表中的department字段维护。

你可能感兴趣的:(mappedBy)