The Disfigured Gem
There was once a wealthy prince whose prized possession was a beautiful and rare gem. Unfortunately, the exquisite gem once fell from its display, and became disfigured with an ugly scratch. The prince, greatly upset, sought the counsel of the kingdom's top jewelers how to restore the gem.
The jewelers reluctantly explained that the scratch was too deep and could not be repaired.
The prince had already decided to store away the gem, when he was approached by a talented craftsman. The craftsman claimed that he had a way to fix the jewel so that there would be no blemish in it. Lacking a better option, the prince entrusted the gem to the artist.
A few days later, the artisan returned with the gem. Sure enough, the scratch was gone. In its place, the craftsman had engraved the design of a beautiful rose. He had made use of the original scratch to form the stem of the rose.
All of the jewelers were amazed by the craftsmanship. With its beautiful and intricate engraving, the gem had become even more valuable.
David's Sin
The Talmud in Avodah Zarah 5a teaches that King David's spiritual and moral level was certainly high enough that he should never have stumbled into taking Batsheva. The sin was predestined by God, so that David's actions would teach future generations the value and effectiveness of teshuvah (repentance).
Like the ugly scratch which was transformed into a beautiful and valuable engraving, David's moral failing was ennobled by his subsequent penitence. David himself became greater and purer because of the incident, and he showed the way for others who stumble to repair their actions.
(Adapted from Mishlei Yaakov pp. 98-99)