首页 > 代码库 > hibernate多对多注解示例
hibernate多对多注解示例
@Entity
@Table(name = "photoGroup")
public class PhotoGroup implements Serializable{
private static final long serialVersionUID = -142542213293758421L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "photoGroupId")
private int photoGroupId;
@ManyToMany(mappedBy="photoGroup",fetch = FetchType.EAGER) //
private Set<Photo> photo;
}
@Entity
@Table(name = "photo")
public class Photo implements Serializable {
private static final long serialVersionUID = -73267813341118015L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "photoid")
private int photoid;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "photo_photoGroup", joinColumns = @JoinColumn(name = "photoid"), inverseJoinColumns = @JoinColumn(name = "photoGroupId"))
private Set<PhotoGroup> photoGroup;
}
参考博客:http://blog.csdn.net/jikak1153/article/details/43865701
hibernate多对多注解示例