Hi, J., you are not alone. My 17 month old has just starting doing this also. He finds it quite funny. I'm pretty much doing the same as you. I tell him "No hitting." "ouch. It hurts." Then I put him down and walk away. He usually cries and follows me. After about 30 seconds (which seems likes 30 hours when your baby is crying for you pick him up!!) I pick him up and repeat, "No hitting". Then I show him (for the hundredth time) how to touch gently. Which he very sweetly does.
Also, it seems he does it when he is being held and is excited. I can kind of tell now before he does it. So I'll hold his hand and say "No, hitting, touch gently" then put him down before he can hit.
It's hard isn't it? It is developmentally appropriate that they are doing this so we can't beat ourselves up over it. No pun intended!! LOL.
Good luck to you.
Kim