It's been a difficult week at Tynecastle with the defection of head coach Craig Levene to Leicester City.
In the circumstances this could have been a difficult fixture for the Hearts players to come through, but first team coach Peter Houston did a brilliant job of bringing the team together in his final game before he joins Levene at Leicester.
Dundee started brightly and had the best of the chances with Craig Gordon in the Hearts goal making two excellent saves to keep score level.
But the turning point came after 25 minutes when Dundee's Hernandez held down Kevin McKenna as he ran on to Ramon Pereira's pass.
It was bad enough for the Dundee man that the referee pointed to the penalty spot, but he also judged that Hernandez was the last man and produced the red card, reducing Dundee to 10 men.
There was an element of relief for Jim Duffy's side when Hearts skipper Steven Pressley rattled the bar from the penalty spot, and indeed they were saved two minutes later by the woodwork again when Kevin McKenna's header from a pinpoint Paul Hartley cross again rebounded off the bar.
But there was no escape for Dundee in the 32nd minute when Pereira found McKenna 10 yards out and the Canadian's right -foot strike was too powerful for Derek Soutar to keep out.
Fabian Caballero almost capitalised on Pressley's error three minutes from the break when he fired a 20-yarder inches wide, but Hearts dominated proceedings after the interval.
Soutar tipped a 20 yarder from McKenna around the post and then Hartley's cross was headed off his own bar by Tom Hutchinson before Bobby Mann cleared off the line.
It was backs to the wall for Dundee, and Soutar denied Alan Maybury before Callum McDonald made a wonderful blocking tackle as Pereira prepared to shoot from 10 yards.
Substitute Grahma Weir sent Hartley through and he drilled in the sweetest of right-foot strikes from a difficult angle.
And substitute Dennis Wyness had the final say when he exchanged a one two with Jamie McAllister and smashed home a right- foot volley from the edge of the box.