They don't, period. Like all rodents, they have a natural ability to swim, but they can tire quickly and drown.
Besides that, all too often they develop respiratory problems as result and chills can kill them.
Hamster use a sand bath to keep themselves clean, look into that.
Only rodent I know that didn't mind swimming was my mouse Yogi, hand raised and after feeding needed bathing. I would sometimes let him swim briefly, then comes the drying well with paper towels and back into his heated nursery.