hibernate多对多注解示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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多对多注解示例的主要内容,如果未能解决你的问题,请参考以下文章

Hibernate---注解多对多

hibernate关于多对多注解配置

Hibernate—— 一对多 和 多对多关联关系映射(xml和注解)总结(转载)

hibernate多对多 一对多 及简单入门

Hibernate、Spring 框架和多对多

Hibernate多对多中间表数据更新问题