Huion
事業向左...愛情向右...失去的...我會在未來期待...
BlogJava
首頁
新隨筆
新文章
聯系
聚合
管理
posts - 1,comments - 3,trackbacks - 0
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2005年6月 (1)
文章分類
Hibernate(1)
J2SE(1)
My Design(1)
問題解決列表(1)
文章檔案
2006年3月 (1)
2005年7月 (1)
2005年6月 (2)
搜索
最新評論
1.?re: J2SE基礎知識之不要依懶Object.equals();
這個是菜鳥都懂啦,哈哈哈哈
--weibo
2.?re: 我的設計之一:利用Java映射和Jdom做通用JavaBean取存
hao
--weibo
3.?re: 我追求...我快樂...
這樣的文章應該放在非技術區!
--dudu
Light Weight 模式的實現
問題提出:
最近項目出現一個Article持久類,該持久類擁有一個Clob屬性用于記錄文章的內容!示例如下:
public
class
Article implements Serializable
{
public
Long articleId;
public
String author;
public
String title;
public
Date created;
public
Clob content;
//
getter
//
setter
}
后來發現,在查找文章列表的時候,每個Article都要從數據庫中加載出content!嚴重影響效率!
解決方案1:
在網上找相關的資料,利用hql可以解決問題:
select
new Article(a.articleId,a.author,a.title,a.created)
from
Article
as
a
where
記得要為 Article 添加構造函數,像上面的hql需要構造函數如:
public
Article(Long articleId,String author,String title,Date create)
{
this
.articleId
=
articleId;
this
.author
=
author;
this
.title
=
title;
this
.create
=
create;
}
解決方案2:
然而這樣子做,列表里面的Article還不夠輕量,于是突然有天在Hibernate官方網站找出更好的解決方法!那就是所謂的Light Weight模式,示例代碼如下:
public
class
ArticleInfo implements Serializable
{
public
Long articleId;
public
String author;
public
String title;
public
Date created;
//
getter
//
setter
}
public
class
Article extends ArticleInfo
{
public
Clob content;
//
getter
//
setter
}
<?
xml version="1.0" encoding="UTF-8"
?>
<!
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
>
<
hibernate-mapping
>
<
class
name
="test.ArticleInfo"
table
="test_article"
polymorphism
="explicit"
>
<
id
name
="articleId"
column
="article_id"
type
="java.lang.Long"
length
="30"
>
<
generator
class
="sequence"
>
<
param
name
="sequence"
>
article_seq
</
param
>
</
generator
>
</
id
>
<
property
name
="authorId"
column
="author_id"
type
="java.lang.String"
length
="10"
not-null
="true"
/>
<
property
name
="title"
column
="title"
type
="java.lang.String"
length
="10"
not-null
="true"
/>
<
property
name
="created"
column
="created"
type
="java.util.Date"
not-null
="true"
/>
</
class
>
</
hibernate-mapping
>
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<!
DOCTYPE hibernate
-
mapping PUBLIC
"
-//Hibernate/Hibernate Mapping DTD 2.0//EN
"
"
http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd
"
>
<
hibernate
-
mapping
>
<
class
name
=
"
test.Article
"
table
=
"
test_article
"
polymorphism
=
"
explicit
"
>
<
id name
=
"
articleId
"
column
=
"
article_id
"
type
=
"
java.lang.Long
"
length
=
"
30
"
>
<
generator
class
=
"
sequence
"
>
<
param name
=
"
sequence
"
>
article_seq
</
param
>
</
generator
>
</
id
>
<
property name
=
"
authorId
"
column
=
"
author_id
"
type
=
"
java.lang.String
"
length
=
"
10
"
not
-
null
=
"
true
"
/>
<
property name
=
"
title
"
column
=
"
title
"
type
=
"
java.lang.String
"
length
=
"
10
"
not
-
null
=
"
true
"
/>
<
property name
=
"
created
"
column
=
"
created
"
type
=
"
java.util.Date
"
not
-
null
=
"
true
"
/>
<
property name
=
"
content
"
column
=
"
content
"
type
=
"
java.sql.Clob
"
not
-
null
=
"
true
"
/>
</
class
>
</
hibernate
-
mapping
>
記得要加上 polymorphism
=
"
explicit
" 表示為多態!
這樣子,當我們需要加載大對象content的時候可以
session.load(Article.class,articleId);
OR
String hql="select a from Article as a where...";
如果,不需要用到大對象,則可以
session.load(ArticleInfo.class,articleId);
OR
String hql="select a from ArticleInfo as a where ...";
posted on 2005-06-12 22:44
一輝
閱讀(161)
評論(0)
編輯
收藏
所屬分類:
Hibernate
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Copyright ©2025 一輝 Powered By
博客園
模板提供:
滬江博客
主站蜘蛛池模板:
亚洲视频一区在线
|
亚洲国产精品人人做人人爱
|
亚洲精品乱码久久久久久中文字幕
|
永久久久免费浮力影院
|
亚洲人成777在线播放
|
57PAO成人国产永久免费视频
|
中文字幕成人免费高清在线视频
|
国产精品亚洲高清一区二区
|
久久久久国色AV免费观看
|
精品亚洲综合在线第一区
|
国产精品视频白浆免费视频
|
91情国产l精品国产亚洲区
|
中文字幕亚洲图片
|
18pao国产成视频永久免费
|
亚洲制服丝袜第一页
|
免费国产综合视频在线看
|
国产精品永久免费视频
|
国产亚洲成AV人片在线观黄桃
|
内射无码专区久久亚洲
|
9420免费高清在线视频
|
黑人粗长大战亚洲女2021国产精品成人免费视频
|
亚洲AV伊人久久青青草原
|
国产国产人免费视频成69大陆
|
亚洲AV无码日韩AV无码导航
|
91在线视频免费91
|
一区视频免费观看
|
亚洲一级免费毛片
|
国产精品亚洲mnbav网站
|
亚洲国产精品狼友中文久久久
|
www国产亚洲精品久久久
|
www.亚洲色图
|
ZZIJZZIJ亚洲日本少妇JIZJIZ
|
亚洲国产一区二区视频网站
|
麻豆国产精品免费视频
|
fc2免费人成在线
|
精品人妻系列无码人妻免费视频
|
国产日韩久久免费影院
|
a毛片在线免费观看
|
国产产在线精品亚洲AAVV
|
亚洲日韩图片专区第1页
|
国产一区在线观看免费
|