Logically speaking, there's no contradiction; the first reference states that the children will be punished, not that they will be put to death, nor share their fathers' guilt.
I tend to be a bit of a "logic cop," I know, but this is an important distinction, since the verses only appear to disagree, at least in this particular translation. It could also be argued that punishment of the children is a side-effect of punishing the fathers... that the punishment of the fathers would be so severe that the effects would be felt four generations down the line, or that the children will inherit their fathers' sinful tendencies. If a father is put to death, I think we would all agree his children will likely be negatively affected, especially if they are old enough to grieve.
There's another line of reasoning, too; "hating god" is described in the Bible as a sin, and if we're talking about "generations of those who hate god," then we may be talking about people who deserve this punishment. Also, grammatically speaking, the word "all" is not implied here; it doesn't say "punishing all children for the sins of the fathers." Not to mention the fact that we're not reading this in the original Hebrew, nor with regard to the appropriate historical and cultural contexts.
There may in fact be logical contradictions in the Bible, or aspects of the Biblical deity which are not perfectly just by our standard, but I'm not sure either is found in this spot. It does seem a little sketchy, but we don't dismiss things because of how they seem - we investigate.