下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Hibernate實(shí)體關(guān)聯(lián)關(guān)系---總結(jié)收集整理:Volunteer20091116版權(quán)聲明:作品,允許,時(shí)請(qǐng)務(wù)必以超形式標(biāo)明文章原始出處、作者信息和本。否則將 。/62575/39398 看了這些是不是后悔浪費(fèi)時(shí)間學(xué)習(xí)映射關(guān)系了?呵呵,Hibernate的ORMap是HibernHibernate在實(shí)際項(xiàng)目開(kāi)發(fā)中,hbm.xml包括數(shù)據(jù)庫(kù)都是通過(guò)Xdoclet生成的,在此不采 關(guān)聯(lián)關(guān)系映射實(shí)例速查HibernateHibernateHibernate關(guān)聯(lián)│││││││││└─多對(duì)多雙向關(guān)聯(lián)WindowsXPProfessionalMySQLHibernateJavaSDK liJIDEA<?xml<?xmlversion='1.0'<!DOCTYPEhibernate-configuration"-//Hibernate/HibernateConfigurationDTD3.0//EN"<property<propertyname="connection.url">jdbc:mysql://localhost:3306/hbstudy</propert<property <property<property<property<property<property<!--EnableHibernate'sautomaticsessioncontextmanagement--<property publicpublicclassHibernateUtilprivatestaticfinalSessionFactorysessionFactory;static{try//CreatetheSessionFactoryfromsessionFactory=new}catch(Throwableex)Makesureyoulogtheexception,asitmightbeswallowedSystem.err.println("初始化SessionFactory失?。?+ex);thrownewExceptionInInitializerError(ex);}}publicstaticfinalThreadLocalsession=newpublicstaticSessiongetCurrentSession()throws{Sessions=(Session)if(s==null||!s.isOpen()){s=sessionFactory.openSession();}return}publicstaticvoidcloseSession()throws{Sessions=(Session)session.get();if(s!=null)}}} 事實(shí)上,單向1-1與N-1的實(shí)質(zhì)是相同的,1-1是N-1的特例,單向1-1與N-1的映射配的配置將與無(wú)連接表N-1關(guān)聯(lián)的many-to-one增加unique="true"屬性即可。 二、實(shí)體(省略getter、setter方法)publicpublic {privateint privateStringname;privateintage;privateAddress11fkpublicpublicclass{privateintaddre privateStringaddressdetail;+|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | +|+||||++|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)|||+||+|||||UNI|++|||+|||+mysql>CREATECREATETABLE`address_11fk` `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULTCREATECREATETABLE_11fk` id`int(11)NOTNULL`name`varchar(255)default`age`int(11)default `int(11)defaultNULL,PRIMARYKEY(` KEY`FK68A8818F3F45AA77` CONSTRAINT`FK68A8818F3F45AA77`FOREIGNKEY `)CES`address_11fk` )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULT在在<many-to-onename="address11fk" "><id "><generatorclass="identity"/><property ><class11fk"<id id"><generatorclass="identity"/><property<property<many-to-onename="address11fk" " publicpublicclassTest_11fk 11fk();Address11fkAddress11fkadd1=newAddress11fk();Sessionsession=HibernateUtil.getCurrentSession();Transactiontx=session.beginTransaction();}}:正常保存推薦這么干Hibernate:insertintoADDRESS_11fk(addressdetail)valuesHibernate:insertinto_11fk(name,age, )values(?,?,Hibernate:insertinto_11fk(name,age,addre )values(?,?,?)Hibernate:insertintoADDRESS_11fk(addressdetail)values(?)Hibernate:update_11fksetname=?,age=?,addre =?wherepersHibernate:insertintoADDRESS_11fk(addressdetail)values:發(fā)生異常,不能保存Hibernate:insertinto_11fk(name,age,addre )values(?,?,?)Exceptioninthread"main"org.hibernate.TransientObjectException:com.lavasofHibernate一對(duì)一主鍵單向關(guān)聯(lián)(見(jiàn)1-1的關(guān)聯(lián)可以基于主鍵關(guān)聯(lián),但基于主鍵關(guān)聯(lián)的持久化類不能擁有自己的主鍵生成策略,one-to-oneone-to-one元素增加constrained="true"屬性,表明該類主鍵由關(guān)聯(lián)類生成。二、實(shí)體(省略getter、setter方法)publicpublic {privateint privateStringname;privateintage;privateAddress11pkpublicpublicclass{privateintaddre privateStringaddressdetail;+|+|++|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | +|+|||++|+id|+++++|Null|Key|Default|Extra+|++|PRI|varchar(255)||+|+||+||++|||++|||+mysql>/*/*Formattedon2007/08/2214:40(QP5v5.50)*/CREATETABLE`address_11pk`( `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre ))ENGINE=InnoDBAUTO_INCREMENT=2DEFAULT/*/*Formattedon2007/08/2214:41(QP5v5.50)*/CREATETABLE` _11pk`(`presonid`int(11)NOT`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(`presonid`),KEY`FK68A882C591BB393E`CONSTRAINT`FK68A882C591BB393E`FOREIGNKEY(`presonid`)REFERENCES`address_11pk` )ENGINE=InnoDBDEFAULT <id<id<generator<param<one-to-onename="address11pk" <class<id id"<generator<param<property<property <id <generator<generator<property publicpublicclassTest_11pkpublicstaticvoid 11pkp1=new Address11pkadd1=newAddress11pk();Sessionsession=HibernateUtil.getCurrentSession();Transactiontx=session.beginTransaction();}}Hibernate:insertintoADDRESS_11fk(addressdetail)valuesHibernate:insertinto_11fk(name,age,addre)values(?,?,Hibernate:insertinto_11fk(name,age,addre)values(?,?,?)Hibernate:insertintoADDRESS_11fk(addressdetail)values(?)Hibernate: _11fksetname=?,age=?,addre=?whereHibernate:insertintoADDRESS_11fk(addressdetail)valuesHibernate:insertinto_11fk(name,age,addre)values(?,?,?) 將N-1many-to-one元素增加unique="true"屬性即可。Address二、實(shí)體(省略getter、setter方法)publicpublic {privateint privateStringname;privateintage;privateAddress11tabpublicpublicclass{privateintaddre privateStringaddressdetail;+|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | +|+|++|+|+|++++++|Null|Key|Default|Extra+++|int(11)||PRI+|+|||address11tab|int(11)|YES|UNI| |+|+++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>/*Formatted/*Formattedon2007/08/2016:52(QP5v5.50)CREATETABLE`join_11tab` id`int(11)NOT`address11tab`int(11)defaultNULL,PRIMARYKEY(` UNIQUEKEY`address11tab`(`address11tab`),KEY`FK6B44BE20C4CC3D33`(`address11tab`),KEY`FK6B44BE209049BB1F`(` id`)REFERENCES `address_11tab` )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2016:53(QP5v5.50)*/CREATETABLE`address_11tab`( `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULT/*Formattedon2007/08/2016:53(QP5v5.50)*/CREATETABLE` _11tab`( id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULT <join<join<key <class<id <generator<property<property <join<key <id <generator<property publicpublicclassTest_11tabpublicstaticvoidmain(String[] 11tabp1=newAddress11tabadd1=newSessionSessionsession=HibernateUtil.getCurrentSession();Transactiontx=session.beginTransaction();}}Hibernate:insertintoADDRESS_11tab(addressdetail)values(?)Hibernate:insertinto_11tab(name,age)values(?,?)Hibernate:insertintojoin_11tab(address11tab, id)values(?,?)Hibernate:insertinto_11tab(name,age)values(?,?)Hibernate:insertintojoin_11tab(address11tab, id)values(?,?)Hibernate:insertintoADDRESS_11tab(addressdetail)values(?)Hibernate:updatejoin_11tabsetaddress11tab=?where Hibernate:insertintoADDRESS_11tab(addressdetail)valuesHibernate:insertinto_11tab(name,age)values(?,?)Hibernate:insertintojoin_11tab(address11tab, id)values(?,?) Hibernate一對(duì)多外鍵單向關(guān)聯(lián)(見(jiàn)將N-1many-to-one元素增加unique="true"屬性即可。(Address二、實(shí)體(省略getter、setter方法)publicpublic 1nfkimplements{privateint privateStringname;privateintage;privateSetaddresses=newpublicpublicclassAddress1nfkimplements{privateintaddre privateString+|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | | |+|MUL|++||+||++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>/*/*Formattedon2007/08/2110:06(QP5v5.50)*/CREATETABLE`address_1nfk`( `int(11)NOTNULL`addressdetail`varchar(255)default`addresses`int(11)defaultPRIMARYPRIMARYKEY KEY`FK9B93456DC08D1667`)ENGINE=InnoDBAUTO_INCREMENT=3DEFAULT/*/*Formattedon2007/08/2110:07(QP5v5.50)*/CREATETABLE` _1nfk`( id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULT <setname="addresses"><key <one-to-many <class<id <generator<property<property <setname="addresses"><key <one-to-many <id <generator<property publicpublicclassTest_1nfk Address1nfk();Address1nfkTransactiontx=session.beginTransaction();}}Hibernate:insertinto_1nfk(name,age)values(?,?)Hibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:updateADDRESS_1nfkset id=?whereaddre=?Hibernate:updateADDRESS_1nfk id=?whereaddreHibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:insertinto_1nfk(name,age)values(?,?)Hibernate:updateADDRESS_1nfkset id=?whereaddre=?Hibernate:updateADDRESS_1nfk id=?whereaddreHibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:insertintoADDRESS_1nfk(addressdetail)valuesHibernate一對(duì)多連接表單向關(guān)聯(lián)(見(jiàn)(Address二、實(shí)體(省略getter、setter方法)publicpublic {privateint privateStringname;privateintage;privateSetaddresses=newpublicpublicclassAddress1nfkimplements{privateint privateString+|+|+|+|+++++|Null|Key|Default|Extra++||+++++|int(11)||int(11)||PRI|PRI+++++||++||+++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>+|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | /*Formatted/*Formattedon2007/08/2110:58(QP5v5.50)*/CREATETABLE`address_1ntab`( `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBAUTO_INCREMENT=3DEFAULT/*Formattedon2007/08/2110:58(QP5v5.50)CREATETABLE`join_1ntab` id`int(11)NOT `int(11)NOTNULL,PRIMARYKEY UNIQUEKEY `KEY`FK6B6078C3C8DF5BFF`KEY`FK6B6078C3C2B11347` )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2110:58(QP5v5.50)CREATECREATETABLE_1ntab` id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULT <class<id <generator<property<property<setname="addresses"><key<!-- <id <generator<property publicpublicclassTest_1ntabpublicstaticvoidmain(String[]Address1ntabAddress1ntabadd1=newAddress1ntab();Address1ntabadd2=newAddress1ntab();Address1ntabadd3=new1ntabp1=new1ntabp2=newadd3.setAddressdetail("安路");Transactiontx=session.beginTransaction();}}1)Hibernate:insertinto_1nfk(name,age)values(?,?)Hibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:insertintoADDRESS_1nfk(addressdetail)values(?)Hibernate:updateADDRESS_1nfksetid=?whereaddre=?Hibernate:updateADDRESS_1nfksetid=?whereaddreHibernate多對(duì)一外鍵單向關(guān)聯(lián)(見(jiàn)多個(gè)人()對(duì)應(yīng)一個(gè)地址(Addresspublicpublic {privateint privateStringname;privateintage;privateAddressn1fkpublicclass{privateintaddre privateStringaddressdetail;||||||Null|Key|Default|||| |PRI||auto_increment|addressdetail|varchar(255)|YES | |||Null|Key|Default|||||+|||PRI||||MUL||auto_increment|varchar(255)|||+||mysql>CREATECREATETABLE`address_n1kf` `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBDEFAULTDROPTABLEIFEXISTSCREATECREATETABLE_n1kf` id`int(11)NOTNULL`name`varchar(255)default`age`int(11)default `int(11)defaultNULL,PRIMARYKEY(` KEY`FK4571AF54A2A3EE48` `address_n1kf` )ENGINE=InnoDBDEFAULT<hibernate-<hibernate-><class<id <generator<property<property<!--用來(lái)映射關(guān)POcolumn是Address在該表中的外鍵<many-to-onename="addressn1fk" </hibernate- <hibernate-><id <generator<property</hibernate- publicpublicclassTest_n1fkpublicstaticvoid n1fkp1=new n1fk Addressn1fkadd=newAddressn1fk();Addressn1fkadd=newAddressn1fk();Transactiontx=session.beginTransaction();}}Hibernate:insertintoADDRESS_n1kf(addressdetail)valuesHibernate:insertinto_n1kf(name,age,addre)values(?,?,?)Hibernate:insertinto_n1kf(name,age,addre)values(?,?,:正常保Hibernate:insertinto_n1kf(name,age,addre)values(?,?,?)Hibernate:insertinto_n1kf(name,age,addre)values(?,?,?)Hibernate:insertintoADDRESS_n1kf(addressdetail)values(?)Hibernate:update_n1kfsetname=?,age=?,addre=?whereid=?Hibernate:update_n1kfsetname=?,age=?,addre=?whereid=?:Hibernate:insertintoADDRESS_n1kf(addressdetail)valuesHibernate:insertinto_n1kf(name,age,addre)values(?,?,?)Hibernate:insertinto_n1kf(name,age,addre)values(?,?,?) Hibernate多對(duì)一連接表單向關(guān)聯(lián)(見(jiàn)多個(gè)人()對(duì)應(yīng)一個(gè)地址(Addresspublicpublic {privateint privateStringname;privateintage;privateAddressn1tabpublicclass{privateintaddre privateStringaddressdetail;|||||Null|Key|Default|||| |PRI||auto_increment|addressdetail|varchar(255)|YES | mysql>desc||||Null|Key|Default|Extra| |int(11)| |PRI|addressn1tab|int(11)|YES|MUL| mysql>mysql> ||||Null|Key|Default||||id|||varchar(255)||||PRI||||auto_incrementCREATETABLECREATETABLE`address_n1tab` `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBAUTO_INCREMENT=2DEFAULTCREATETABLE`join_n1tab` id`int(11)NOT`address11fk`int(11)defaultNULL,PRIMARYKEY(` KEY`FKAC780AAADAE3A82C` CONSTRAINT`FKAC780AAAC6242A64`FOREIGNKEY(`address11fk`)`address_n1tab` _n1tab` )ENGINE=InnoDBDEFAULTCREATETABLE_n1tab` id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBAUTO_INCREMENT=3DEFAULT<hibernate-<hibernate-><classn1tab"<id <generator<property<property<!--使用join元素顯式確 表--<join<!--映射關(guān)聯(lián)<key<key<many-to-one</hibernate- <hibernate-<hibernate-><classname="com.lavasoft.dx._n_1_tab.Addressn1tab"<id <generator<property</hibernate- publicpublicclassTest_n1tabpublicstaticvoidmain(String[] n1tabp1=new n1tabp2=newAddressn1tabadd=newAddressn1tab();Transactiontx=session.beginTransaction();}Hibernate:insertintoADDRESS_n1tab(addressdetail)values(?)Hibernate:insertinto_n1tab(name,age)values(?,?)Hibernate:insertintojoin_n1tab(address11fk, id)values(?,?)Hibernate:insertinto_n1tab(name,age)values(?,?)Hibernate:insertintojoin_n1tab(address11fk, id)values(?,?):正常保Hibernate:insertinto_n1tab(name,age)values(?,?)Hibernate:insertintojoin_n1tab(address11fk, id)values(?,?)Hibernate:insertinto_n1tab(name,age)values(?,?)Hibernate:insertintojoin_n1tab(address11fk, id)values(?,?)Hibernate多對(duì)多單向關(guān)聯(lián)(見(jiàn)二、實(shí)體(省略getter、setter方法)publicpublic {privateint privateStringname;privateintage;privateSetaddresses=newpublicpublicclass{privateintaddre privateStringaddressdetail;++|++|+++++|Null|Key|Default|+++++|+mysql>||||+id|| |PRI||auto_increment|varchar(255)||+|+||+||+||+||++|+||+|+||++|++++++|Null|Key|Default|Extra+++|int(11)||int(11)||PRI|PRI+++++||++||++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>/*Formatted/*Formattedon2007/08/2111:13(QP5v5.50)*/CREATETABLE`address_nn`( `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBAUTO_INCREMENT=4DEFAULT/*Formattedon2007/08/2111:14(QP5v5.50)CREATETABLE`join_nn` id`int(11)NOT `int(11)NOTNULL,PRIMARYKEY(` KEY`FKAAB98CF5E008E752`KEY`FKAAB98CF5239F6A16`CONSTRAINT`FKAAB98CF5239F6A16`FOREIGNKEY `)REFERENCES CONSTRAINT`FKAAB98CF5E008E752`FOREIGNKEYid`)REFERENCES)ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2111:14(QP5v5.50)CREATETABLE _nn```id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBAUTO_INCREMENT=3DEFAULT <classnn"<id <generator<property<property><key<!-- <id <generator<property publicpublicclassTest_nnpublicstaticvoidmain(String[]args){Addressnnadd1=newAddressnn();AddressnnAddressnn();Addressnnnnnnnnadd3.setAddressdetail("安路");Sessionsession=}}Hibernate:insertintoADDRESS_nn(addressdetail)values(?)Hibernate:insertintoADDRESS_nn(addressdetail)values(?)Hibernate:insertintoADDRESS_nn(addressdetail)values(?)Hibernate:insertinto_nn(name,age)values(?,?)Hibernate:insertinto_nn(name,age)values(?,?)Hibernate:insertintojoin_nn(id,addre)values(?,?)Hibernate:insertintojoin_nn(id,addre)values(?,?)Hibernate:insertintojoin_nn(id,addre)values(?,?)Hibernate:insertintojoin_nn(id,addre)values(?, /*DBMS MySQL /*Created 2008-12-9 droptableifexistsaddress;droptableifexists /*Table: createtableaddress bigintnotnullauto_incrementcommentID', varchar(120)notnullcomment'詳細(xì)地址', bigintcomment人的ID',primarykey(id))type=altertableaddresscomment'地址/* createtable bigintnotnullauto_incrementcomment'ID', varchar(24)notnullcomment' primaryprimarykey)type=alter comment'人altertableaddressaddconstraintFK_Reference_4foreignkey (id)ondeleterestrictonupdatepublicpublic implements{privateLongprivateStringname;privateAddressaddress;publicclassAddressimplements{privateLongid; privateString<?xml<?xmlversion="1.0"encoding="utf-0//EN"PUBLIC"-//Hibernate/HibernateDTD><class "<idname="id"<columnname="id"<generatorclass="identity"<propertyname="name"<columnname="name"length="24"not- <one-to-onename="address"cascade="all" <?xmlversion="1.0"encoding="utf-0//EN"PUBLIC"-//Hibernate/HibernateDTD><classname="entity.Address"table="address"<idname="id"<<columnname="id"<generatorclass="identity"<propertyname="detail"<columnname="detail"length="120"not-<many-to-onename=" "class="entity. fetch="select"unique="true"><column <?xml<?xmlversion='1.0'encoding='UTF-<!DOCTYPEhibernate-configuration"-//Hibernate/HibernateConfigurationDTD3.0//EN"<!--GeneratedbyMyEclipseHibernate<property<propertyname="connection.url"><propertyname="dialect"><property<propertyname="connection.driver_class"><property<property.hbm.xml"importimportorg.hibernate.Transaction;importentity.Address;import importpublicclassTestpublicstaticvoidmain(String[]{ }publicstaticvoid{=Addressaddress=newAddress("XXX號(hào) Sessionsession=HibernateSessionFactory.getSession();Transactiontx=session.beginTransaction(); } (?,Hibernate /*DBMS MySQL /*Created 2008-12-8 droptableifexistsaddress;droptableifexists /*Table: createtableaddress bigintnotnullcomment varchar(120notnullcomment'詳細(xì)地址',primarykey(id))type=altertableaddresscomment'地址/*/*create(bigintnotnullauto_incrementcommentvarchar(24)notnullcommentprimarykey)type=altercomment'人altertableaddressaddconstraintFK_Reference_2foreignkey (id)ondeleterestrictonupdatepublicpublic implements{privateLongid;privateStringname;privateAddressaddress;publicclassAddressimplements{privateLongid; privateString<?<?xmlversion="1.0"encoding="utf-0//EN"PUBLIC"-//Hibernate/HibernateDTD><class "<idname="id"<columnname="id"<generatorclass="identity"<propertyname="name"<columnname="name"length="24"not- <!--cascade="all":在保存 對(duì)象關(guān)聯(lián)的address對(duì)象 <one-to-onename="address"cascade="all"><?<?xmlversion="1.0"encoding="utf-<!DOCTYPEhibernate-map"PUBLIC"-//Hibernate/HibernateDTD><classname="entity.Address"table="address"<idname="id"<columnname="id"<generator<param <propertyname="detail"<columnname="detail"length="120"not- <one-to-one "constrained="true" <?<?xmlversion='1.0'encoding='UTF-<!DOCTYPEhibernate-configuration"-//Hibernate/HibernateConfigurationDTD3.0//EN"<!--GeneratedbyMyEclipseHibernate<property<propertyname="connection.url"><propertyname="dialect"><<property<propertyname="connection.driver_class"><property<property.hbm.xml" 一對(duì)一連接表雙向關(guān)聯(lián)(見(jiàn)public {privateint privateStringname;privateintage;privateAddress11tab_sxAddpublic {privateint privateStringname;privateintage;privateAddress11tab_sxpublicpublicclass{privateintaddre privateStringaddressdetail; ++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>+|+|+|+||++|++++++|Null|Key|Default|Extra+++|int(11)|id|int(11)||UNI|PRI+++++||++||++|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | /*Formatted/*Formattedon2007/08/2217:35(QP5v5.50)*/CREATETABLE` _11tab_sx`( id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2217:34(QP5v5.50)*/CREATETABLE`address_11tab_sx`( `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2218:35(QP5v5.50)CREATETABLE`join_11tab_sx` `int(11)NOT id`int(11)NOTNULL,PRIMARYKEY(` UNIQUEKEY `UNIQUEKEY id`KEY`FKF4AA80E44327AAB6`KEY`FKF4AA80E460C0C9F0` `address_11tab_sx` _11tab_sx` ))ENGINE=InnoDBDEFAULT <class<id <generator<property<property<keycolumn=" <many-to-one <id <generator<property<keycolumn="addre <many-to-onename=" 11tab_sx"column=" not-null="true"unique="true"/> publicpublicclassTest_11tab_sxpublicstaticvoidmain(String[]args){Address11tab_sxadd=new 11tab_sxp=Sessionsession=Transactiontx=session.beginTransaction();}}1)Hibernate:insertinto_11tab_sx(name,age)values(?,?)Hibernate:insertintoADDRESS_11tab_sx(addressdetail)values(?)Hibernate:insertintojoin_11tab_sx(addre,id)values(?,?) (ddress二、實(shí)體(省略getter、setter方法)publicpublic 1nfk_sximplements{privateint privateStringname;privateintage;privateSetaddresses=newpublicpublicclassAddress1nfk_sximplements{privateintaddre privateStringaddressdetail;++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>+|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | | |+|MUL++||+||+/*/*Formattedon2007/08/2217:42(QP5v5.50)CREATETABLE`address_1nfk` `int(11)NOTNULL`addressdetail`varchar(255)default id`int(11)defaultNULL,PRIMARYKEY(`addre KEY`FK9B93456DA6D6C1F5` )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2217:42(QP5v5.50)*/CREATETABLE` _1nfk`( id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBDEFAULT <class1nfk_sx"<id<id<key id"not- <id <column id"not- publicpublicclassTest_1nfk_sxpublicstaticvoidmain(String[]args){Address1nfk_sxadd1=newAddress1nfk_sx();Address1nfk_sxadd2=new 1nfk_sxp=new Sessionsession=HibernateUtil.getCurrentSession();Transactiontx=session.beginTransaction();}}1)正常保存Hibernate:insertintoADDRESS_1nfk_sx(addressdetail,id)values(?,?)Hibernate:insertintoADDRESS_1nfk_sx(addressdetail,id)values(?,?) 一對(duì)多連接表雙向關(guān)聯(lián)(見(jiàn)public {privateint privateStringname;privateintage;privateSetaddresses=newApublic {privateint privateStringname;privateintage;privateSetaddresses=newpublicpublicclass{privateintaddre privateStringaddressdetail; ++|+|||++|+id|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|varchar(255)||+|+||+||+||+||+mysql>+|+|+|+|+|+|++++|Null|Key|Default|+|++++|+|PRI||auto_increment|addressdetail|varchar(255)|YES | +|+|+|+||++|++++++|Null|Key|Default|Extra+++|int(11)|id|int(11)||PRI|PRI+++++||++||+/*Formatted/*Formattedon2007/08/2217:52(QP5v5.50)*/CREATETABLE`address_1ntab_sx`( `int(11)NOTNULL`addressdetail`varchar(255)defaultNULL,PRIMARYKEY(`addre )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2217:52(QP5v5.50)*/CREATETABLE` _1ntab_sx`( id`int(11)NOTNULL`name`varchar(255)default`age`int(11)defaultNULL,PRIMARYKEY(` )ENGINE=InnoDBDEFAULT/*Formattedon2007/08/2217:52(QP5v5.50)CREATETABLE`join_1ntab_sx` `int(11)NOT id`int(11)NOTPRIMARYKEY(` KEY`FK8F869F61F93DDD6`(` KEY`FK8F869F61FC0F682A`(`addre `address_1ntab_sx` )ENGINE=InnoDBDEFAULT <class<id <generator<prop
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 湖南省多校聯(lián)考2024-2025學(xué)年高二上學(xué)期12月聯(lián)考政治試題(含答案)
- 《解析工傷保險(xiǎn)》課件
- 孕期屁股疼的健康宣教
- 孕期肚臍發(fā)黑的健康宣教
- 分泌性中耳炎的健康宣教
- 絲狀角膜病變的臨床護(hù)理
- 羊水過(guò)多的健康宣教
- 星跡步態(tài)的健康宣教
- 腺垂體功能減退癥的臨床護(hù)理
- 中耳癌的健康宣教
- 建設(shè)宜居宜業(yè)和美鄉(xiāng)村
- 職業(yè)技能大賽-食品安全管理師競(jìng)賽理論知識(shí)題及答案
- 農(nóng)村活動(dòng)廣場(chǎng)實(shí)施方案村文化小廣場(chǎng)建設(shè)的實(shí)施方案
- 2024簡(jiǎn)易租房合同下載打印
- 2024-2030年中國(guó)船只燃料行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略分析報(bào)告
- 2024年浙江高考技術(shù)試題(含答案)
- TBSES 001-2024 建設(shè)項(xiàng)目環(huán)境影響后評(píng)價(jià)技術(shù)指南 污染影響類
- 《財(cái)務(wù)會(huì)計(jì)學(xué)(第14版)》課后參考答案 戴德明
- (2024)醫(yī)師定期考核法律法規(guī)必刷題庫(kù)及答案
- 人音版音樂(lè)二年級(jí)上冊(cè)《小紅帽》說(shuō)課稿
- 人教版(PEP)英語(yǔ)四年級(jí)上冊(cè)《Unit 1 My classroom》單元教學(xué)設(shè)計(jì) 1
評(píng)論
0/150
提交評(píng)論