When an object is on a pivot and you wish to rotate it, it becomes a little harder because you can't simply rotate from it's centre. You need to rotate from it's pivot point.
Take the following situation:
Situation
Explanations
1) Before rotating the object, calculate the joint position.
2) Rotate the object.
3) Calculate the new position of the joint.
4) Compute the delta and add it to the object position.
Code
Enjoy !