无连接表的双向1-n关联,和单项关联

来源:互联网 发布:男神执事团类似网络剧 编辑:程序博客网 时间:2024/05/29 04:54

无连接表的双向1-n关联

@OneToMany(targetEntity=Address.class,mappedBy="person")//因为是控制关系,所以可以不用写cascade=CascadeType.ALL

private Set<Address> address=new HashSet<Address>();


Address段

@ManyToOne(targetEntity=person.Class,cascade=CascadeType.ALL)

@JoinColumn(name="person_id",referencedColumnName="person_id",nullable=false)

private Person person



单项关联  1-n关联


@OneToMany(targetEntity=Address.class.cascade=CascadeType.ALL)

@JoinColumn(name="address_id",referencedColumnName="address_id",nullable=false)

private Set<Address> address=new HashSet<Address>();



对于address是一个基本Entity类,没有person的应用

看看数据表

感觉是差不多,都是关系控制在N端

对我们的双向访问有一定的差距


http://blog.csdn.net/sweatott/article/details/62930314

0 0