is it though? you’re training people so they can be competent at the job they’ve been hired for and then they what take their skills and go do the same thing at a different company? Why would they do that when they already have a job at your company? There must be a reason for them to be leaving in sufficient numbers to cause you problems…
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.