欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

hibernate映射二

系統 1705 0

<!-- [if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><!-- [if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1030"/> </xml><![endif]--><!-- [if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]-->

繼承映射

Animal

Id

name

Sex

Weight

Height

Type

1

小豬

True

100

?

P

2

小鳥

False

?

20

B

Extends.hbm.xml 如下:

< hibernate-mapping package = "com.test.hibernate" >

??? < class name = "Animal" table = "animal" >

?????? < id name = "id" >

?????????? < generator class = "native" ></ generator >

?????? </ id >

??? ??? < property name = "name" ></ property >

?????? < property name = "sex" ></ property >

?????? < discriminator column = "type" type = "string" />

?????? < subclass name = "Pig" discriminator-value = "P" >

?????????? < property name = "weight" ></ property >

?????? </ subclass >

?????? < subclass name = "Bird" discriminator-value = "B" >

?????????? < property name = "height" ></ property >

?????? </ subclass >

??? </ class >

</ hibernate-mapping >

?

Animal animal =(Animal)session.load(animal.Class, 1);

?????? if (animal instanceof Pig) {

?????????? System. out .println( "Pig" );

??????????

?????? }

?

當用 Pig 去加載時是可以的,用父類 Animal 去加載也可以,但是 load 默認是 lazy 加載,用 Animal 加載的是 animal 代理類不是真正的 Pig

如果你把 class 中的 lazy=”false”, 則用 Animal 加載的是是真正的 Pig 類(多態)

get() 方法和 sql 查詢支持多態查詢,返回的是真正的 Pig

Sql 的“ from java.lang.Object ”是查到所有的實體類對象;

2 每個類一張映射表

animal

Id

Name

sex

1

小豬

True

2

小鳥

false

? pig

pid

weight

1

100

bird

bid

height

1

10

Extends.hbm.xml 如下:

< hibernate-mapping package = "com.test.hibernate" >

??? < class name = "Animal" table = "animal" >

?????? < id name = "id" >

?????????? < generator class = "native" ></ generator >

?????? </ id >

?????? < property name = "name" ></ property >

?????? < property name = "sex" ></ property >

?????? <join- subclass name = "Pig" table=”pig” >

?????????? <key column=”pid” />

?????????? < property name = "weight" ></ property >

?????? </ join- subclass >

?????? < join- subclass name = "Bird" table=”bird” >

?????????? <key column=”bid” />

?????????? < property name = "height" ></ property >

?????? </ join- subclass >

??? </ class >

這種對象模型不變而存儲模型的方法變了;缺點是建表多,效率低;

如果 User 對象的一些屬性也是其他對象的屬性(即他們有許多共同的屬性),因此將共同的屬性提取成為一個公用的類(此類包含了共同的屬性)如:

public class User {

??? private int id ;

??? private Contact conta ct ;

?

}

//set,get 方法略

public class Contact {

private String name ;

private boolean sex ;

}

//set,get 方法略

User.hbm.xml 如下:

< hibernate-mapping package = "com.test.hibernate" >

??? < class name = "User" table = "user" >

?????? < id name = "id" >

?????????? < generator class = "native" ></ generator >

?????? </ id >

?????? <component name= "contact">

?????????? < property name = "name" ></ property >

?????? ??? < property name = "sex" ></ property >

?????? </component>

??? </ class >

對關系模型沒有任何影響,這樣適合復用;

復合主鍵映射

通常將復合主鍵相關的屬性放到一個單獨的類中,這個是有約束的:

l ?????? 必須實現序列化接口

l ?????? 必須寫 hashCode() equals()

public class User {

??? private int age ;

??? private PK composite ;// 復合主鍵

?

}

//set,get 方法略

public class PK {

private String name ;

private boolean sex ;

}

//set,get 方法略

User.hbm.xml 如下:

< hibernate-mapping package = "com.test.hibernate" >

??? < class name = "User" table = "user" >

?????? <composite-id name= " composite ">

?????? ??? <key- property name = "name" ></key- property >

?????? ??? <key- property name = "sex" ></key- property >

</composite-id>

< property name = "name" ></ property >

?????? ??? </ class >

集合的映射

t_collection_mapping

id

name

1

xxx

t_set_values

set_id

set_value

1

A

1

b

t_list_values

list_id

list_value

list_index

1

c

0

1

d

hibernate映射二


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 岛国毛片一级一级特级毛片 | 涩涩色综合亚洲悠悠色 | 欧美久久久久 | 69p69永久网址 | 日本高清在线观看视频www | 国产日韩一区二区三区在线观看 | 久久福利青草精品免费 | 久久久久久久久淑女av国产精品 | 国产在线第一区 | 伦一区二区三区中文字幕v亚洲 | 一级三级黄色片 | 国产中文字幕在线 | 99精品免费久久久久久久久日本 | 国产免费久久精品99 | 亚洲热色| 日本玖玖 | 国产主播福利精品一区二区 | 成人在线精品视频 | 亚洲欧美日韩精品一区 | A片欧美乱妇高特黄AA片片 | 一级做a爰片久久毛片唾 | 日日摸夜夜添欧美一区 | 91精品一区二区综合在线 | 国产欧美一区二区久久 | 国产精品美女久久久久久 | 新白娘子传奇50集免费赵雅芝版 | 久热国产在线视频 | 亚洲免费精品 | 久久大香香蕉国产免费网站 | 一级@片| 国内外成人免费视频 | 国产精品综合色区小说 | 久久久人成影片免费观看 | av网站观看| 成人免费网站视频 | 亚洲国产一二三 | 五月婷婷天堂 | 日韩在线免费观看视频 | 欧美美女动态图 | 香港三日本三级三级三级 | 精品久久久久久久久久 |