Janáček wrote this opera between 1903 and 1905. His daughter Olga had died shortly before he began to compose it. He had also just finished his opera "Jenůfa" which has a tragic ending for the young girl in the story.