有3张表,calendar,calendar_user,user
calendar_user为中间表只保存calendar_id,user_id,calendar_user表没有实体对象,
private Set<User> users;
@ManyToMany(
targetEntity=User.class,
cascade={CascadeType.PERSIST}//防止删除子时删除父
)
@JoinTable(
name="calendar_user",
joinColumns={@JoinColumn(name="calendar_id")},
inverseJoinColumns={@JoinColumn(name="user_id")}
)
public Set<User> getUsers() {
return users;
}
public void setUsers(Set<User> users) {
this.users= users;
}