Molecules are hydrophilic or hydrophobic.
Hydrophilic molecules of polar or ionic compounds break up into ions and form hydrogen bonds with water. The water molecules then create a sphere of hydration around these individual ions and keep them dispersed.
But hydrophobic compounds and repel water molecules. The hydrogen bonding pattern of the water shifts to create a clathrate around the hydrophobic compound. This cage-like structure prevents the substance from dissolving.