Dear
If your stomach hurts while sleeping only then it might not be just the stomach which can be the cause of the pain but the
liver or the ribs might be the reason.
Since it is long standing, you need to get it evaluated.
Next Steps
Get a xray chest and sonography upper abdomen
Health Tips
Don't worry it might be some trivial cause and you will get better soon.