Hibernate檢索策略學習之--批量加載
系統
1716 0
所謂批量加載,即把原本要發送的SQL分批統一發送,比如說原本要發送100條SQL,如果設置batch-size=3,則只需要發送100/3+1=34條,可以提高效率
批量加載分為延遲加載和立即加載,先說立即加在
首先建立測試數據庫
?
CREATE
?
TABLE
?certificate?(
??id?
varchar
(
100
)?
NOT
?
NULL
?
default
?
''
,
??description?
varchar
(
100
)?
default
?
''
,
??
PRIMARY
?
KEY
??(id)
);
CREATE
?
TABLE
?student?(
??team_id?
varchar
(
100
)?
default
?
''
,
??id?
varchar
(
100
)?
NOT
?
NULL
?
default
?
''
,
??name?
varchar
(
20
)?
default
?
''
,
??cardId?
varchar
(
20
)?
NOT
?
NULL
?
default
?
''
,
??age?
int
(
11
)?
default
?
'
0
'
,
??
PRIMARY
?
KEY
??(id)
);
CREATE
?
TABLE
?team?(
??id?
varchar
(
100
)?
NOT
?
NULL
?
default
?
''
,
??teamName?
varchar
(
100
)?
default
?
''
,
??
PRIMARY
?
KEY
??(id)
);
INSERT
?
INTO
?student?
VALUES
?
(
'
5
'
,
'
1
'
,
'
spark
'
,
'
200211332
'
,
13
),
(
'
4
'
,
'
2
'
,
'
jerry
'
,
'
200233332
'
,
23
),
(
'
3
'
,
'
3
'
,
'
adidas
'
,
'
200231332
'
,
33
),
(
'
2
'
,
'
4
'
,
'
zhouxingchi
'
,
'
200231132
'
,
43
),
(
'
1
'
,
'
5
'
,
'
tomclus
'
,
'
200512345
'
,
53
),
(
'
1
'
,
'
6
'
,
'
tom
'
,
'
200511345
'
,
63
);
INSERT
?
INTO
?team?
VALUES
?
(
'
5
'
,
'
team5
'
),
(
'
4
'
,
'
team4
'
),
(
'
3
'
,
'
team3
'
),
(
'
2
'
,
'
team2
'
),
(
'
1
'
,
'
team1
'
);
INSERT
?
INTO
?certificate?
VALUES
?
(
'
1
'
,
'
card1
'
),
(
'
2
'
,
'
card2
'
),
(
'
3
'
,
'
card3
'
),
(
'
4
'
,
'
card4
'
),
(
'
5
'
,
'
card5
'
),
(
'
6
'
,
'
card6
'
);
?
建立POJO對象
?
package
?Search.immediately;
public
?
class
?Certificate?.........
...
{
????
private
?String?id;
????
private
?String?description;
????
private
?Student?stu;
????
public
?Student?getStu()?.........
...
{
????????
return
?stu;
????}
????
public
?
void
?setStu(Student?stu)?.........
...
{
????????
this
.stu?
=
?stu;
????}
????
public
?String?getDescription()?.........
...
{
????????
return
?description;
????}
????
public
?
void
?setDescription(String?description)?.........
...
{
????????
this
.description?
=
?description;
????}
????
public
?String?getId()?.........
...
{
????????
return
?id;
????}
????
public
?
void
?setId(String?id)?.........
...
{
????????
this
.id?
=
?id;
????}
}
package
?Search.immediately;
import
?java.util.HashSet;
import
?java.util.Set;
public
?
class
?Team?.........
...
{
????
private
?String?id;
????
private
?Set?students
=
new
?HashSet();
????
private
?String?teamName;
????
private
?Set?tests;
??
????
public
?Set?getTests()?.........
...
{
????????
return
?tests;
????}
?
????
public
?
void
?setTests(Set?tests)?.........
...
{
????????
this
.tests?
=
?tests;
????}
????
public
?String?getId()?.........
...
{
????????
return
?id;
????}
????
public
?
void
?setId(String?id)?.........
...
{
????????
this
.id?
=
?id;
????}
????
public
?String?getTeamName()?.........
...
{
????????
return
?teamName;
????}
????
public
?
void
?setTeamName(String?name)?.........
...
{
????????
this
.teamName?
=
?name;
????}
????
public
?Set?getStudents()?.........
...
{
????????
return
?students;
????}
????
public
?
void
?setStudents(Set?students)?.........
...
{
????????
this
.students?
=
?students;
????}
}
package
?Search.immediately;
public
?
class
?Certificate?.........
...
{
????
private
?String?id;
????
private
?String?description;
????
private
?Student?stu;
????
public
?Student?getStu()?.........
...
{
????????
return
?stu;
????}
????
public
?
void
?setStu(Student?stu)?.........
...
{
????????
this
.stu?
=
?stu;
????}
????
public
?String?getDescription()?.........
...
{
????????
return
?description;
????}
????
public
?
void
?setDescription(String?description)?.........
...
{
????????
this
.description?
=
?description;
????}
????
public
?String?getId()?.........
...
{
????????
return
?id;
????}
Hibernate檢索策略學習之--批量加載
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元