Hibernate自動生成工具Schema怎么用

這篇文章主要介紹Hibernate自動生成工具Schema怎么用,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司2013年開創(chuàng)至今,先為章丘等服務(wù)建站,章丘等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為章丘企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

Hibernate Schema自動生成可以從你的映射文件使用一個Hibernate工具生成DDL。 生成的schema包含有對實(shí)體和集合類表的完整性引用約束(主鍵和外鍵)。涉及到的標(biāo)示符生成器所需的表和sequence也會同時(shí)生成。

在使用這個工具的時(shí)候,你必須 通過hibernate.dialet屬性指定一個SQL方言(Dialet),因?yàn)镈DL是與供應(yīng)商高度相關(guān)的。

首先,要定制你的映射文件,來改善生成的Hibernate schema。對Hibernate schema定制化(Customizing the schema)

很多Hibernate映射元素定義了可選的length、precision 或者 scale屬性。你可以通過這個屬性設(shè)置字段的長度、精度、小數(shù)點(diǎn)位數(shù)。

<property name="zip" length="5"/> <property name="balance" precision="12" scale="2"/>

有些tag還接受not-null屬性(用來在表字段上生成NOT NULL約束)和unique屬性(用來在表字段上生成UNIQUE約束)。

<many-to-one name="bar" column="barId" not-null="true"/> <element column="serialNumber" type="long" not-null="true" unique="true"/>

unique-key屬性可以對成組的字段指定一個***鍵約束(unique key constraint)。目前,unique-key屬性指定的值在生成DDL時(shí)并不會被當(dāng)作這個約束的名字,它們只是在用來在映射文件內(nèi)部用作區(qū)分的。

<many-to-one name="org" column="orgId" unique-key="OrgEmployeeId"/> <property name="employeeId" unique-key="OrgEmployee"/>

index屬性會用對應(yīng)的字段(一個或多個)生成一個index,它指出了這個index的名字。如果多個字段對應(yīng)的index名字相同,就會生成包含這些字段的index。

<property name="lastName" index="CustName"/> <property name="firstName" index="CustName"/>

foreign-key屬性可以用來覆蓋任何生成的外鍵約束的名字。

<many-to-one name="bar" column="barId" foreign-key="FKFooBar"/>

很多映射元素還接受子元素。這在定義跨越多字段的類型時(shí)特別有用。

<property name="name" type="my.customtypes.Name"/>     <column name="last" not-null="true" index="bar_idx" length="30"/>     <column name="first" not-null="true" index="bar_idx" length="20"/>     <column name="initial"/> property>

default屬性為字段指定一個默認(rèn)值 (在保存被映射的類的新實(shí)例之前,你應(yīng)該將同樣的值賦于對應(yīng)的屬性)。

<property name="credits" type="integer" insert="false">     <column name="credits" default="10"/> property> <version name="version" type="integer" insert="false">     <column name="version" default="0"/> property>

sql-type屬性允許用戶覆蓋默認(rèn)的Hibernate類型到SQL數(shù)據(jù)類型的映射。

<property name="balance" type="float">     <column name="balance" sql-type="decimal(13,3)"/> property>

check屬性允許用戶指定一個約束檢查。

<property name="foo" type="integer">       <column name="foo" check="foo > 10"/>   property>   <class name="Foo" table="foos" check="bar < 100.0">       ...        <property name="bar" type="float"/>   class>

以上是“Hibernate自動生成工具Schema怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

標(biāo)題名稱:Hibernate自動生成工具Schema怎么用
本文URL:http://bm7419.com/article6/jcchig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、微信公眾號關(guān)鍵詞優(yōu)化、企業(yè)建站、網(wǎng)頁設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名