Redian新闻
>
问一个Collection Update的问题
avatar
问一个Collection Update的问题# Java - 爪哇娇娃
A*o
1
如果你有setter要把一个Collection更新到db里面,
Collection里面没有的从数据库里面删除,
两边都有的,更新,
Collection单方面有的插入。
有没有什么design pattern来处理类似问题?
avatar
B*g
2
问题:database里的数据有啥用?全删了再全加进去不是很好?

【在 A**o 的大作中提到】
: 如果你有setter要把一个Collection更新到db里面,
: Collection里面没有的从数据库里面删除,
: 两边都有的,更新,
: Collection单方面有的插入。
: 有没有什么design pattern来处理类似问题?

avatar
A*o
3
看来只有这个样子了……:(

【在 B*****g 的大作中提到】
: 问题:database里的数据有啥用?全删了再全加进去不是很好?
avatar
g*g
4
If you use hibernate, just set all-delete-orphan in the
one to many relationship and it's automatic.

【在 A**o 的大作中提到】
: 如果你有setter要把一个Collection更新到db里面,
: Collection里面没有的从数据库里面删除,
: 两边都有的,更新,
: Collection单方面有的插入。
: 有没有什么design pattern来处理类似问题?

avatar
A*o
5
thanks, other than hibernate ne?

【在 g*****g 的大作中提到】
: If you use hibernate, just set all-delete-orphan in the
: one to many relationship and it's automatic.

avatar
h*n
6

nod

【在 B*****g 的大作中提到】
: 问题:database里的数据有啥用?全删了再全加进去不是很好?
avatar
F*n
7
Use a persistent Collection implementation. Hibernate has one. You don't
want to do it yourself because it has been done and it will be a waste of
time.

【在 A**o 的大作中提到】
: thanks, other than hibernate ne?
avatar
F*n
8
If you have thousands of records you don't want rewrite them each time you
update the DB.

【在 h****n 的大作中提到】
:
: nod

avatar
B*g
9
That will be depends.
Based on LZ's case, I believe rewrite is much faster than checking each
record exists or not.

【在 F****n 的大作中提到】
: If you have thousands of records you don't want rewrite them each time you
: update the DB.

avatar
g*g
10
Not necessarily, if performance is your concern, a solution like
Hibernate + JBoss Cache can eliminate all unneccesary writing.
In most products for most cases, you change a small portion of
records every time.

【在 B*****g 的大作中提到】
: That will be depends.
: Based on LZ's case, I believe rewrite is much faster than checking each
: record exists or not.

avatar
B*g
11
you sure check a dup will be faster than add a new one?

【在 g*****g 的大作中提到】
: Not necessarily, if performance is your concern, a solution like
: Hibernate + JBoss Cache can eliminate all unneccesary writing.
: In most products for most cases, you change a small portion of
: records every time.

avatar
B*g
12
sorry, correct it.
Rename the table, the recreate same table, then load.

【在 B*****g 的大作中提到】
: 问题:database里的数据有啥用?全删了再全加进去不是很好?
avatar
g*g
13
Depends, your record may be big. You may be able to play tricks like
lazy-loading, prefetching with ORM, you'll save a ton of read with ORM
caching. In any case, it's always easier and cheaper to cluster the
application server and make the DB server the bottleneck.
If you are really talking about highly scalable application, that's
the direction you go, avoid extra DB read/write at all cost.

【在 B*****g 的大作中提到】
: you sure check a dup will be faster than add a new one?
avatar
B*g
14
Still can loading by clustered application server.

【在 g*****g 的大作中提到】
: Depends, your record may be big. You may be able to play tricks like
: lazy-loading, prefetching with ORM, you'll save a ton of read with ORM
: caching. In any case, it's always easier and cheaper to cluster the
: application server and make the DB server the bottleneck.
: If you are really talking about highly scalable application, that's
: the direction you go, avoid extra DB read/write at all cost.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。