Generation of entanglement in cavity QED