Water is an excellent solvent due to its high dielectric constant. Substances that mix well and dissolve in water are known as hydrophilic ("water-loving") substances, while those that do not mix well with water are known as hydrophobic ("water-fearing") substances. The ability of a substance to dissolve in water is determined by whether or not the substance can match or better the strong attractive forces that water molecules generate between other water molecules. If a substance has properties that do not allow it to overcome these strong intermolecular forces, the molecules are precipitated out from the water. Contrary to the common misconception, water and hydrophobic substances do not "repel", and the hydration of a hydrophobic surface is energetically, but not entropically, favorable.
When an ionic or polar compound enters water, it is surrounded by water molecules (hydration). The relatively small size of water molecules (~ 3 angstroms) allows many water molecules to surround one molecule of solute. The partially negative dipole ends of the water are attracted to positively charged components of the solute, and vice versa for the positive dipole ends.
In general, ionic and polar substances such as acids, alcohols, and salts are relatively soluble in water, and nonpolar substances such as fats and oils are not. Nonpolar molecules stay together in water because it is energetically more favorable for the water molecules to hydrogen bond to each other than to engage in van der Waals interactions with non-polar molecules.
An example of an ionic solute is table salt; the sodium chloride, NaCl, separates into  cations and  anions, each being surrounded by water molecules. The ions are then easily transported away from their crystalline lattice into solution. An example of a nonionic solute is table sugar. The water dipoles make hydrogen bonds with the polar regions of the sugar molecule (OH groups) and allow it to be carried away into solution.