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