then maybe you should stop training people; or think for a second that if you are the one training everybody you can take a little less profit in exchange for starving your competitors of trained employees. Besides it works itself out anyway if they stay on longer even though it takes you longer to recoup your training costs. tldr this training argument is full of contradictions
but they don't stay longer. and unfortunately a pleasant work environment doesn't help because juniors don't know yet that other companies are different. it takes working for a few companies before someone learns to value work culture over a higher salary.
that's the challenge, especially for foreign companies trying to hire locals. in china big companies pay good salaries but they also often don't have a good work culture. i got better results hiring juniors who have not yet experienced that work culture. at least in china students do learn programming so they are not poorly trained. a friend of mine tried that in another country and could not make it work.