This question comes up quiet often here in Yahoo Answers, and the answer is always the same...
It starts with a question: did you have sex with your ex? If the answer is "yes" something happened at a deeper spiritual level that people are not aware of...
When God told mankind to abstain from sex unless it is your spouse and you are married, it is because he knew that in the spiritual dimension they become one flesh when they have sex:
6 “But at the beginning of creation God ‘made them male and female.’[a] 7 ‘For this reason a man will leave his father and mother and be united to his wife,[b] 8 and the two will become one flesh.’[c] So they are no longer two, but one flesh. 9 Therefore what God has joined together, let no one separate.” Mark 10
That means that you may live separated physically now, but in the soul / spirit dimension you are still one, you are still married to him spiritually. Since dreams are spiritual it is not unusual to dream about your spiritual husband every once in a while.
How do you stop this? The only way is repentance.
You need to get before your knees before God and Jesus Christ, and repent for having sex (fornication) with someone else other than your spouse. Ask him to forgive you and the also separate you spiritually. You need to renounce that covenant in the spirit.
In case the ex was actually a spouse and you are having sex with someone else...same thing....you are still one flesh in the spirit, but in this case it is called adultery. God says the only valid excuse for a divorce is infidelity. If this happened to you also repent to God for all your sins, and ask him to set you free from your ex if he is the one that cheated on you.
God is real. His spiritual laws are real. Heaven is real. Hell is real.
Please repent. Nothing in this world is worth being separated from him for all eternity.
How to accept Jesus Christ as your personal Savior and Lord?
It is the easiest thing in the world. Just close your eyes, focus on him and pray something like this:
"Lord Jesus, I repent of all my sins and I ask you to wash me clean. I am sorry for all the bad things I have done and the many times I broke God's Will. Please forgive me and fill me with the gift of the Holy Spirit. I want to belong to God. I want to be adopted into his family as his son/daughter. I want to get to know you. I want a relationship with you. Come into my heart. I give you control over my life. Please lead me through the Holy Spirit and make your Word real to me. Fill my soul with the peace that surpasses understanding and help me change so that I may lead a life that is pleasing to you. I want to go to heaven and I want to be called by the Fathers name. As of today I declare that I belong to you". Amen
If you do this with all of your heart you will start noticing subtle changes inside of you and step by step your life will change. I am speaking from experience.