The Tang and Song dynasties expanded the civil service exam to replace the nine-rank system which favored hereditary and largely military aristocrats.
In practice, however, gentry families were more able to educate their sons and used their connections with local officials to protect their interests.
By late imperial China, merchants used their wealth to educate their sons in hopes of entering the civil service.
Financially desperate gentry married into merchant families which led to a breakdown of the old class structure.
Mao Zedong led the way in attacking "bad gentry and local bullies" for collecting high rent and oppressing their tenants during the Republican period.