A**o 发帖数: 1550 | 1 如果你有setter要把一个Collection更新到db里面,
Collection里面没有的从数据库里面删除,
两边都有的,更新,
Collection单方面有的插入。
有没有什么design pattern来处理类似问题? |
B*****g 发帖数: 34098 | 2 问题:database里的数据有啥用?全删了再全加进去不是很好?
【在 A**o 的大作中提到】 : 如果你有setter要把一个Collection更新到db里面, : Collection里面没有的从数据库里面删除, : 两边都有的,更新, : Collection单方面有的插入。 : 有没有什么design pattern来处理类似问题?
|
A**o 发帖数: 1550 | 3 看来只有这个样子了……:(
【在 B*****g 的大作中提到】 : 问题:database里的数据有啥用?全删了再全加进去不是很好?
|
g*****g 发帖数: 34805 | 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来处理类似问题?
|
A**o 发帖数: 1550 | 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.
|
h****n 发帖数: 101 | 6
nod
【在 B*****g 的大作中提到】 : 问题:database里的数据有啥用?全删了再全加进去不是很好?
|
F****n 发帖数: 3271 | 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?
|
F****n 发帖数: 3271 | 8 If you have thousands of records you don't want rewrite them each time you
update the DB.
【在 h****n 的大作中提到】 : : nod
|
B*****g 发帖数: 34098 | 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.
|
g*****g 发帖数: 34805 | 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.
|
B*****g 发帖数: 34098 | 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.
|
B*****g 发帖数: 34098 | 12 sorry, correct it.
Rename the table, the recreate same table, then load.
【在 B*****g 的大作中提到】 : 问题:database里的数据有啥用?全删了再全加进去不是很好?
|
g*****g 发帖数: 34805 | 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?
|
B*****g 发帖数: 34098 | 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.
|