zoukankan      html  css  js  c++  java
  • hibernate one2one 联合主键关联 composite key

    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;
    import javax.persistence.PrimaryKeyJoinColumn;

    @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;
    }

    //@JoinColumn(name="wife_id")
    @OneToOne
    @JoinColumns(        //这里要先 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;
    }

    }

    ``````````````````````````````````````````````````````````````````

    package com.bjsxt.hibernate;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.IdClass;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinColumns;
    import javax.persistence.OneToOne;

    @Entity
    @IdClass(WifePK.class)
    public class Wife {
    @Id
    private int id;
    @Id
    private String name;
    private String age;


    public String getAge() {
    return age;
    }
    public void setAge(String age) {
    this.age = age;
    }

    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;
    }

    }

    ·································································

    package com.bjsxt.hibernate;


    public class WifePK {
    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;
    }

    }

  • 相关阅读:
    oracle11G静默安装步骤
    [INS06101] IP address of localhost could not be determined
    linux tar命令使用详解
    centos 安装 Adobe Flash Player
    yum出错:Error: failure: repodata/filelists.xml.gz from googlechrome: [Errno 256] No more mirrors to try.
    sysbench安装与使用
    /usr/libexec/gconfsanitycheck2 退出状态256
    sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
    Oracle11gR2 for Linux 静默安装
    error while loading shared libraries: xxx.so.0:cannot open shared object file: No such file or directory
  • 原文地址:https://www.cnblogs.com/lize1215/p/7641018.html
Copyright © 2011-2022 走看看