Is surgery the only recourse of prosthetic device? Total hip replacement done 5 years ago. Stem has loosened. How is it repaired? Who should do this?

Revision needed. If the stem has become loose from the femur and is causing pain, a revision is indicated. This should be done by a surgeon trained or well experienced in doing these procedures. While the outcome of this procedure can be very good, it is technically more difficult than the primary replacement and the recovery can be longer.
Yes. A loose stem can only be corrected by revision surgery. The old stem is removed, the fibrous scar tissue is scraped away from the inside of the bone, and a new, larger more robust stem is used. You should seek treatment with an experienced fellowship trained joint replacement surgeon who does more than 50 revisions per year.
Generally. Orthopedic surgeon will repair your hardware. Speak with another surgeon if you are not planning to see the surgeon that initially did this surgery. They can help you determine what is the best treatment for you.
Loosening . Loosening of a hip prosthesis is something that needs to be evaluated closely. Most important is to explain the nature of the loosening. This usually requires multiple x-rays and laboratory tests to differentiate between septic & aseptic loosening, while evaluating all implanted components. Additionally, your history, activity and body habitus all need to be taken into account. Because the stem has loosened, it would be a good idea for you to use crutches or an assist device to offload weight from the affected limb. This should also decrease any discomfort that you're experiencing as well. Once a full work-up has been completed, your orthopedic surgeon can then proceed with a revision of the appropriate components.