Hibernate-----One-to-one shared primary key association mappings (annotations)

Source: Internet
Author: User

One (' many ')

Import Javax.persistence.cascadetype;import Javax.persistence.entity;import javax.persistence.GeneratedValue; Import Javax.persistence.id;import Javax.persistence.onetoone;import org.hibernate.annotations.GenericGenerator; Import Org.hibernate.annotations.Parameter;    @Entitypublic class Wife {private int id;     private String name;     Private Husband Husband; /** * Wife ID is assigned according to husband ID, the ID generator must be set to the foreign * * parameter specified wife ID is used in the husband object ID */@Id @GenericG Enerator (name = "Pkgenerator", strategy = "foreign", parameters = {@Parameter (name = "Property", value = "husband")}) @    Generatedvalue (generator = "pkgenerator") 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;    } public void Sethusband (Husband Husband) {this.husband = Husband; } @OneToOne (cascade = Cascadetype.all)    Public Husband Gethusband () {return Husband; }}

One (' one ')

Import Javax.persistence.cascadetype;import Javax.persistence.entity;import javax.persistence.GeneratedValue; Import Javax.persistence.id;import Javax.persistence.onetoone;import javax.persistence.PrimaryKeyJoinColumn; @Entitypublic class Husband {    private int id;    private String name;    Private Wife Wife;     @Id    @GeneratedValue Public    int getId () {       return Id;    }     Public String GetName () {       return name;    }     This annotation can only be written at one end of the main (build ID)    @OneToOne (cascade = cascadetype.all)    @PrimaryKeyJoinColumn 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;    






Hibernate-----One-to-one shared primary key association mappings (annotations)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.