• hibernate 联合主键关联


    package com.bjsxt.hibernate;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    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 String getName() {
            return name;
        }
        @OneToOne
        @JoinColumns(
            {
                @JoinColumn(name="wifeId", referencedColumnName="id"),
                @JoinColumn(name="wifeName", referencedColumnName="name")
            }
        )

        public Wife getWife() {
            return wife;
        }
        public void setId(int id) {
            this.id = id;
        }
        public void setName(String name) {
            this.name = name;
        }
        public void setWife(Wife wife) {
            this.wife = wife;
        }
       
    }

     

     

     

    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.IdClass;

    @Entity
    @IdClass(WifePK.class)
    public class Wife {
        private int id;
        private String name;
        private int age;
       
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
        @Id
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        @Id
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
       
    }


     

    import java.io.Serializable;

     

    public class WifePK implements Serializable {
        private int id;
        private String name;
       
       
        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;
        }
       
    }

  • 相关阅读:
    js文字跳动效果
    js文字效果
    centos7安装Logwatch配合msmtp邮件客户端发送服务器监控分析日志
    子查询
    Hexo添加字数统计、阅读时长
    基于visual Studio2013解决C语言竞赛题之0523魔方阵
    基于visual Studio2013解决C语言竞赛题之0522和为素
    基于visual Studio2013解决C语言竞赛题之0521圆盘求和
    基于visual Studio2013解决C语言竞赛题之0520相邻元素
    基于visual Studio2013解决C语言竞赛题之0519最大值
  • 原文地址:https://www.cnblogs.com/flying607/p/3478101.html
Copyright © 2020-2023  润新知