Not all types of businesses necessarily require the establishment of a legal entity in mainland China.
Whether a legal entity is needed in mainland China depends on your business, your objectives, as well as the specific industry in which you operate. In general, it is needed for businesses that require payments to be made and received in China without paying intermediary fees, for those requiring a large number of employees in the country, as well as for those involving production or R&D activities. If you are an exporter of products/services, you can work with Chinese clients through distribution agreements or licensing agreements without requiring to be legally present in China; but being present on the ground allow companies to follow more closely their operations and develop local networks, for instance through a simple representative office.
Many foreign investors may also choose to register a company in Hong Kong SAR as an entry point to mainland China. The advantages include: less market entry restrictions, the use of English as official language in contracts and business, internationally-renowned litigation and arbitration mechanisms, less constraints in terms of movement of capital and people, as well as generally easier access to capital. Official guidelines (in English) on how to register a company in Hong Kong were produced by the local government and can be accessed at this link.