zoukankan      html  css  js  c++  java
  • 11、基于annotation的onetoone的配置

    基于annotation的onetoone的配置

    IDCard.java

    package org.zttc.itat.model;
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    
    @Entity
    @Table(name="t_id_card")
    public class IDCard {
        private int id;
        private String no;
        private Person person;
        
        @Id
        @GeneratedValue
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getNo() {
            return no;
        }
        public void setNo(String no) {
            this.no = no;
        }
        @OneToOne
        @JoinColumn(name="pid")
        public Person getPerson() {
            return person;
        }
        public void setPerson(Person person) {
            this.person = person;
        }
    }

    Person.java

    package org.zttc.itat.model;
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    
    @Entity
    @Table(name="t_person")
    public class Person {
        private int id;
        private String name;
        private IDCard idCard;
        
        @OneToOne(mappedBy="person")
        public IDCard getIdCard() {
            return idCard;
        }
        public void setIdCard(IDCard idCard) {
            this.idCard = idCard;
        }
        
        @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;
        }
    }
  • 相关阅读:
    Centos7运维(1)-为什么在centos7配置了静态IP不生效还是分配一个动态ip给我??
    docker 常用命令
    docker 安装
    centos6.8 修改yum安装镜像源
    开发自己的composer package
    修改mysql密码
    MySQL密码的恢复方法
    nginx配置文件说明
    天猫优惠券
    mysql的一些心得
  • 原文地址:https://www.cnblogs.com/zhangbaowei/p/4868410.html
Copyright © 2011-2022 走看看