The proximate reason for China getting involved in Korea was self-defense. It has been rather convincingly argued that if it weren't Truman and Douglas MacArthur's insistence on going all the way to the Yalu River (the border between North Korea and China), China would never have intervened militarily [1]. This is despite repeated warnings from China that they would intervene if US troops continued driving north, warnings which were completely ignored by Truman and his war cabinet [2].
The US had repeatedly sworn to not cross the 38th parallel in the past. Once the US decided to invade North Korea proper, Truman's promises to stop at the Yalu River no longer seemed credible to China's government. Note that Beijing is very close to Manchuria, and both the Manchus and Japanese invaded China along this route in the past.
The US has certainly threatened war against any foreign powers that interfered anywhere in the entire Western hemisphere [3] -- not sure how anyone can then turn around and fault China for reacting to American troops driving right up to its Manchurian border. Remember this was in 1951, the Cold War was getting warmed up, and the US had nuked Japan only a few years earlier. No responsible Chinese government could have ignored the very real and credible threat of another invasion.
The Vietnamese invasion has an interesting history -- the PLA invaded, failed to achieve its main objectives, then marched right back less than a month later. Certainly not a full-scale invasion nor an occupation, considering the proximate cause was to 'punish' Vietnam for invading Cambodia.
Also, 80,000 Chinese soldiers invaded Vietnam in 1978, with the intention to take Hanoi. It was by no means a minor skirmish.