3.2. Making objects persistent
Once you've created a new entity instance (using the common
new
operator) it is in the new state. You can make it persistent by associating it to an entity manager:
DomesticCat fritz = new DomesticCat(); fritz.setColor(Color.GINGER); fritz.setSex('M'); fritz.setName("Fritz"); em.persist(fritz);
If the
DomesticCat
entity type has a generated identifier, the value is associated to the instance when persist()
is called. If the identifier is not automatically generated, the application-assigned (usually natural) key value has to be set on the instance before persist()
is called.