A multi-pair association of two-way relationship mappings

Source: Internet
Author: User

A multi-pair association of two-way relationship mappings

 PackageOrg.fkjava.bean;Importjava.util.Date;ImportJava.util.Set;/*** One-to-many foreign-key bi-directional correlation relationship configuration * A person an address * *@authorHanfeili * www.fkjava.org*/ Public classPerson {PrivateInteger ID; PrivateString name; Private intpassword; PrivateDate birthday; //A set collection holds multiple address references    PrivateSet<address>AddressSet;  PublicPerson () {} @Override PublicString toString () {return"Person [id=" + ID + ", name=" + name + ", password=" +Password+ ", birthday=" + Birthday + "]"; }             PublicSet<address>Getaddressset () {returnAddressSet; }     Public voidSetaddressset (set<address>AddressSet) {         This. AddressSet =AddressSet; }     PublicInteger getId () {returnID; }     Public voidsetId (Integer id) { This. ID =ID; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     Public intGetPassword () {returnpassword; }     Public voidSetPassword (intpassword) {         This. Password =password; }     PublicDate Getbirthday () {returnbirthday; }     Public voidsetbirthday (Date birthday) { This. Birthday =birthday; }}---------------------------------------------------------------------- PackageOrg.fkjava.bean;/*** One-to-many foreign-key bidirectional affinity configuration * *@authorHanfeili www.fkjava.org*/ Public classAddress {PrivateInteger ID; /*** ZIP Code*/    PrivateString codes; /*** Specific Address*/    PrivateString des; //because it is a bidirectional association, the address class needs to be//I want a person in the middle.    Privateperson person ; @Override PublicString toString () {return"Address [id=" + ID + ", codes=" + Codes + ", des=" + des + "]"; }     PublicString getcodes () {returncodes; }     Public voidsetcodes (String codes) { This. Codes =codes; }     PublicString getdes () {returndes; }     Public voidsetdes (String des) { This. des =des; }     PublicPerson Getperson () {returnPerson ; }     Public voidSetperson (person person) { This. person =Person ; }     PublicInteger getId () {returnID; }     Public voidsetId (Integer id) { This. ID =ID; }}
<?XML version= "1.0"?><!DOCTYPE hibernate-mapping SYSTEM "Http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><!--One -to-many foreign-key bidirectional affinity configuration --<hibernate-mapping Package= "Bean">-<classTable= "T_person"name= "Person">-<IDname= "id"><Generatorclass= "Identity"/></ID>< Propertyname= "Name"/>< Propertyname= "Password"/>< Propertyname= "Birthday"/><!--Configuring the Association of multiple addresses for a person by set inverse=true indicates that the relationship is not maintained on the people side --<Setname= "AddressSet"Inverse= "true"Cascade= "All"><!--specifies that the data in the Adddrssset collection corresponds to a foreign key of T_person -<Keycolumn= "p_id"/><!--Specify the instance type that the person is associated with -<One-to-manyclass= "Address"/></Set></class>-<classTable= "T_address"name= "Address">-<IDname= "id"><Generatorclass= "Identity"/></ID>< Propertyname= "Codes"/>< Propertyname= "des"/><!--not-null= "True" specifies that the foreign key cannot be null -<Many-to-onename= "Person"column= "p_id"Not-null= "true"/></class></hibernate-mapping>

A multi-pair association of two-way relationship mappings

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.