According to the “Protoevangelium of James,” Joachim was a wealthy man. But when Joachim went to the temple to offer his gifts, as was the custom of his people, he was refused entrance. He was told that since he had no children, he was not worthy to offer his gifts to God. Joachim even researched the Twelve Tribes of Israel, and found out that he was the only one of the righteous men who did not have a child. This greatly disturbed him, and instead of going home to his wife, Anna, he went out into the wilderness for forty days and forty nights and fasted, living only on prayer.
Anna then mourned for both the loss of her husband and for being childless. But because it was a time of celebration in the Jewish faith, Anna cleaned herself up and put on her wedding garments. She then went out into the garden, sat under a tree, and prayed to God to bless her with a child. Just as Anna was lamenting, an angel appeared to her and told her that God had heard her prayer and that she would conceive and bear a child. Anna rejoiced and said she would bring her child as an offering to God to minister all the days of his/her life.
Then two angels came to Anna and told her that Joachim was returning. An angel had also appeared to Joachim and told him to go home because his prayer had been answered and his wife would conceive a child. More
The story continues that on the next day, he returned to the temple with his offering of gifts, and this time his offering was accepted. He left the temple and went home rejoicing and giving glory to God. After nine months, Anna bore a daughter, whom she named Mary.