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