Ways Session.save user entity objects to the database persistence operations. In other words, Session.save method call with the entity object by matching Insert SQL, data insert database table. Ways Session.save contains the following major steps:
1. At Session internal cache find to be the object of preservation. Internal cache hit, then consider this data has been preserved (insert operations performed), already in Persistent Object entity status, a direct return. At this point, even before the data relative status has changed, will also be submitted at a later transaction, the dirty data from the inspection process be judged, and judged the results to decide whether to implement the corresponding Update operation.
2. If the entity class implementation of the Lifecycle interface, then call the object to be preserved onSave method.
3. If the entity class implementation of the Validatable interface, then call the validate method
4. To call the corresponding method Interceptor.onSave interceptors (if any)
5. Tectonic Insert SQL, and implement
5. Record successfully inserted, physical object id has been set back not insert new record operation id value
7. The user object Add the internal cache. Is worth mentioning here that when the save method does not put physical objects into the secondary cache, because through the save method of preservation of the entity object, in the affairs of the remainder of the probability of being modified is often very high, cache frequently updated and the subsequent from the cost of data synchronization problem, has exceeded this data reuse possible revenue losses.
8. The best, if there is cascaded relationship, the relationship between the recursive cascaded treatment.







