How does one prevent orchitis?

Random mostly. Since orchitis is mostly from bacterial infection and is somewhat of arandom occurrence, there isn't much to do in the way of "prevention". If you are diabetic and more prone to infection, i would say that good diabetes control would be important in reducing infection risk in general.