A one-to-one relationship between hibernate

Source: Internet
Author: User
Tags generator key reference return string tostring
There are two types of maintenance for one-to-one relationships, and there are two types of maintenance for one-to-one relationships between primary key associations and unique foreign Key associations: (bidirectional) Association of primary Key associations (bi-directional)  Person.javaPerson {     private string username;    //reference to the accused party     private  address address;    public string getusername ()  {         return username;    }     Public void setusername (String username)  {         this.username = username;    }    public address  GetAddress ()  {        return address;     }    public void setaddress (address address)  {    &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;THIS.ADDRESS=&NBSP;ADDRESS;&NBSP;&NBSP;&NBSP;&NBSP}} (passive side)   Address.javaaddress{    private string addressname;    //reference to the main control party     private  Person person;    public string getaddressname ()  {         return addressname;    }    public  void setaddressname (String addressname)  {         this.addressname= addressname;    }    public person  Getperson ()  {        return person;    }     public void setperson (Person person)  {         this.person= person;    }    public  String tostring ()  {        return new  Tostringbuilder (this).  &nbsP;      append ("Addressname",  addressname) .         tostring ();     }        public  boolean equals (Object o)  {        if  (  ! (o instanceof address)   {             return false;           }         Address rhs =  (address)  o;           return new equalsbuilder ()                            .appendsuper (Super.equals (o))                           .append (This.addressname, rhs.getaddressname ())                            .isequals ();    }    public  Int hashcode ()  {        return new hashcodebuilder (17, 37).         append (Addressname) .         tohashcode ();    }}mapping  file <class name= "person"  table= "Person" ><id name= "id"  type= "long"  column= "id" ><generator class= " Native "/></id><property name=" "username"  column= "username"  type= "string"/>< One-to-onename= ' address ' class= ' address ' cascade= ' all ' constrained= ' false '/></class><class name= "Address"  table= "address" ><id name=" id " column=" id "><generator class=" foreign ">                        <param name= "Property" >person</param>                   </generator>         </id>        <one-to-one name= "Person"  class= "Person"  constrained= "true"/><property name= "Addressname"  column= "AddressName" " type=" string/></class>

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.