po类Husband.java
package com.hibernate.demo.po; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; @Entity public class Husband { private int id; private String name; private Wife wife; @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @OneToOne @JoinColumn(name="wife_id") public Wife getWife() { return wife; } public void setWife(Wife wife) { this.wife = wife; } }
po类Wife
package com.hibernate.demo.po; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToOne; /** * 凡是双向外键关联,一定设置mappedBy * @author apprentice * */ @Entity public class Wife { private int id; private String name; private Husband husband; @OneToOne(mappedBy="wife") //Husband是主导 public Husband getHusband() { return husband; } public void setHusband(Husband husband) { this.husband = husband; } @Id public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
相关推荐
博文链接:https://shaqiang32.iteye.com/blog/201312
NULL 博文链接:https://cdxs2.iteye.com/blog/1930749
hibernate one-to-one 一对一唯一外键关联映射_单向 and 双向
NULL 博文链接:https://huihai.iteye.com/blog/1243558
NULL 博文链接:https://12345678.iteye.com/blog/723871
NULL 博文链接:https://cdxs2.iteye.com/blog/1930748
NULL 博文链接:https://lijunabc.iteye.com/blog/438972
NULL 博文链接:https://cdxs2.iteye.com/blog/1932507
博文链接:https://shaqiang32.iteye.com/blog/201311
博文链接:https://llying.iteye.com/blog/220807
NULL 博文链接:https://paladin1988.iteye.com/blog/1657564
http://blog.csdn.net/e421083458/article/details/8794127 该源码为Hibernate教程配套源码
Hibernate 一对一外键单向...Hibernate 一对一外键双向关联 Hibernate 一对一主键双向关联 Hibernate 一对一连接表双向关联 Hibernate 一对多外键双向关联 Hibernate 一对多连接表双向关联 Hibernate 多对多双向关联
Hibernate想要实现双向的关联就必须在映射文件的两端同时配置,另外还要在主映射的一端采用foreign外键关联属性,下面我们就一起来看一下Java的Hibernate框架中的双向主键关联与双向外键关联方法:
hibernate外键实现一对一双向关联关系源码
博文链接:https://llying.iteye.com/blog/220804
grails生成的ddl.sql,整理出其中的外键关联关系