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

Hibernate中抽象化主鍵使用教程

系統(tǒng) 2010 0

首先,在數(shù)據(jù)庫(kù)中建立表:
CREATE TABLE `container` (
? `containerId` varchar(50) NOT NULL,
? `container_type` varchar(50) NOT NULL,
? `size` double default NULL,
? `name` varchar(50) default NULL,
? `description` varchar(50) default NULL,
? `height` double default NULL,
? `length` double default NULL,
? `width` double default NULL,
? `diameter` double default NULL,
? PRIMARY KEY? (`containerId`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;

?

其中Container是一個(gè)抽象類(lèi),其下有兩個(gè)子類(lèi)Box和Bottle

?

package ?abstracttest;

public ? abstract ? class ?Container? ... {
??
private ?String?containerId;
??
private ? double ?size;
??
private ?String?name;
??
private ?String?description;
public ?String?getContainerId()? ... {
????
return ?containerId;
}

public ? void ?setContainerId(String?containerId)? ... {
????
this .containerId? = ?containerId;
}

public ?String?getDescription()? ... {
????
return ?description;
}

public ? void ?setDescription(String?description)? ... {
????
this .description? = ?description;
}

public ?String?getName()? ... {
????
return ?name;
}

public ? void ?setName(String?name)? ... {
????
this .name? = ?name;
}

public ? double ?getSize()? ... {
????
return ?size;
}

public ? void ?setSize( double ?size)? ... {
????
this .size? = ?size;
}

}

?

package ?abstracttest;

public ? class ?Bottle? extends ?Container? ... {
??
private ? double ?diameter;
??
private ? double ?height;
public ? double ?getDiameter()? ... {
????
return ?diameter;
}

public ? void ?setDiameter( double ?diameter)? ... {
????
this .diameter? = ?diameter;
}

public ? double ?getHeight()? ... {
????
return ?height;
}

public ? void ?setHeight( double ?height)? ... {
????
this .height? = ?height;
}

}

?

package ?abstracttest;

public ? class ?Box? extends ?Container? ... {
????
private ? double ?height;
????
private ? double ?length;
????
private ? double ?width;
????
public ? double ?getHeight()? ... {
????????
return ?height;
????}

????
public ? void ?setHeight( double ?height)? ... {
????????
this .height? = ?height;
????}

????
public ? double ?getLength()? ... {
????????
return ?length;
????}

????
public ? void ?setLength( double ?length)? ... {
????????
this .length? = ?length;
????}

????
public ? double ?getWidth()? ... {
????????
return ?width;
????}

????
public ? void ?setWidth( double ?width)? ... {
????????
this .width? = ?width;
????}

}

?

在HBM文件中,定義,抽象類(lèi)的配置

?

<? xml?version="1.0"?encoding="utf-8" ?>
<! DOCTYPE?hibernate-mapping?PUBLIC?"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!-- ?
????Mapping?file?autogenerated?by?MyEclipse?-?Hibernate?Tools
-->
< hibernate-mapping? package ="abstracttest" >
????
< class? name ="Container" ?abstract ="true" ?table ="container" >
???????
< id? name ="containerId" >
?????????
< generator? class ="uuid.hex" ></ generator >
???????
</ id >
???????
< discriminator? column ="container_type" ></ discriminator >
???????
< property? name ="size" ?column ="size" ></ property >
???????
< property? name ="name" ?column ="name" ></ property >
???????
< property? name ="description" ?column ="description" ></ property >
???????
< subclass? name ="Box" ?discriminator-value ="BOX" >
?????????
< property? name ="height" ?column ="height" ></ property >
?????????
< property? name ="width" ?column ="width" ></ property >
?????????
< property? name ="length" ?column ="length" ></ property >
???????
</ subclass >
???????
< subclass? name ="Bottle" ?discriminator-value ="BOTTLE" >
?????????
< property? name ="diameter" ?column ="diameter" ></ property >
?????????
< property? name ="height" ?column ="height" ></ property >
???????
</ subclass >
????
</ class >
</ hibernate-mapping >

?

最后是測(cè)試代碼

package ?abstracttest;

import ?org.hibernate.Session;
import ?org.hibernate.SessionFactory;
import ?org.hibernate.Transaction;
import ?org.hibernate.cfg.Configuration;


public ? class ?Test? ... {

????
/**?*/ /**
?????*?
@param ?args
?????
*/

????
public ? static ? void ?main(String[]?args)? ... {
????????Configuration?cfg
= new ?Configuration();
????????cfg.configure();
????????SessionFactory?sf
= cfg.buildSessionFactory();
????????Session?session
= sf.openSession();
????????Transaction?t
= session.beginTransaction();
????????Box?box1
= new ?Box();
????????box1.setName(
" 木箱子 " );
????????box1.setHeight(
50 );
????????box1.setLength(
50 );
????????box1.setWidth(
50 );
????????box1.setDescription(
" 包裝電視機(jī) " );
????????box1.setSize(
12500 );
????????
????????Bottle?bottle1
= new ?Bottle();
????????bottle1.setName(
" 玻璃瓶子 " );
????????bottle1.setDescription(
" 喝牛奶用 " );
????????bottle1.setSize(
139.12 );
????????bottle1.setDiameter(
6 );
????????bottle1.setHeight(
12 );
????????
????????sessio

Hibernate中抽象化主鍵使用教程


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 一本色道精品久久一区二区三区 | 亚洲国产天堂久久综合226 | 午夜激情爱爱 | 国内精品视频在线观看 | 久久噜噜噜精品国产亚洲综合 | 久久伊人中文字幕有码 | 精品国产一区二区在线 | 国产福利资源在线 | 欧美黄色一区 | 欧美精品在线一区二区三区 | 一区二区三区在线观看视频 | 国产日韩第一页 | 日本一区午夜爱爱 | 国产传媒在线视频 | 久草视| 午夜久久久 | 99久久99热久久精品免费看 | 国产精品亚洲va在线观看 | 欧美一区二区三区在线观看视频 | 亚洲奇米| 精品无人乱码一区二区三区 | 一级黄色片播放 | 伦理二区| 婷婷在线观看网站 | 国产一级免费视频 | 亚洲免费在线观看视频 | 99re在线| 九九热在线视频 | 日本熟妇毛茸茸xxxxx | 国产日韩欧美一区 | 在线看免电影网站 | 国产精品1区2区 | 国产精品天天天天影视 | 四虎国产成人免费观看 | 色阁阁日韩欧美在线 | 亚洲区国产区 | 日韩在线不卡视频 | 在线观看特色大片免费网站 | 欧美 日产 国产精品 | 免费日本视频 | 亚洲欧美一区二区三区国产精品 |