Many-to-many bidirectional associations of relational mappings

Source: Internet
Author: User

Many-to-many bidirectional associations of relational mappings

 PackageOrg.fkjava.bean;ImportJava.util.Set;/*** Multi-to-many bi-directional affinity configuration * *@authorHanfeili www.fkjava.org*/ Public classAddress {PrivateInteger ID; /*** ZIP Code*/    PrivateString codes; /*** Specific Address*/    PrivateString des; PrivateSet<person>Personset; @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; }         PublicSet<person>Getpersonset () {returnPersonset; }     Public voidSetpersonset (set<person>Personset) {         This. Personset =Personset; }     PublicInteger getId () {returnID; }     Public voidsetId (Integer id) { This. ID =ID; }}----------------------------------------------------------------------- PackageOrg.fkjava.bean;Importjava.util.Date;ImportJava.util.Set;/*** Multi-to-many bi-directional affinity configuration * * *@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; }}

Configuration file

<?XML version= "1.0"?><!DOCTYPE hibernate-mapping SYSTEM "Http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><!--configuration of many-to-many bidirectional affinity relationships --<hibernate-mapping Package= "Bean">-<classTable= "T_person"name= "Person">-<IDname= "id"><Generatorclass= "Identity"/></ID>< Propertyname= "Name"/>< Propertyname= "Password"/>< Propertyname= "Birthday"/><!--Table specifies an intermediate table name in many-to-many configurations in which the intermediate table names should be consistent --<SetTable= "Join_person_addrss"name= "AddressSet"Inverse= "true"><!--using p_id to correlate _person data in an intermediate table -<KeyNot-null= "true"column= "p_id"/><!--Specify the association relationship between the T_pseron table and t_address using A_ID maintenance -<Many-to-manyclass= "Address"column= "a_id"/></Set></class>-<classTable= "T_address"name= "Address">-<IDname= "id"><Generatorclass= "Identity"/></ID>< Propertyname= "Codes"/>< Propertyname= "des"/>-<SetTable= "Join_person_addrss"name= "Personset"><KeyNot-null= "true"column= "a_id"/><Many-to-manyclass= "Person"column= "p_id"/></Set></class></hibernate-mapping>

Many-to-many bidirectional associations of relational 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.