The idea of MyBatis hibernate was abandoned.
Anyway, the stickers are first. Hibernate three status bits and switching between the use of functions;
Summarize the functions of saveorupdate (), Save (), update (), merge ().
Save (), update (): It's all very well understood.
Save () generates a record in the database and, if there is one in the database, an error message that there is a duplicate record.
Update () is the updating of records in the database;
Merge () is very wonderful:
1. If there is an instance of the same persistence identifier (identifier) in the session, overwrite the old persistent instance with the state of the object given by the user;
2. If the session does not have a corresponding persistent instance, attempt to load from the database or create a new persisted instance;
3. Finally returns the persistent instance;
4. The user gives the object is not linked to the session, it is still off the tube;
Merge () Reference: http://blog.csdn.net/lang_man_xing/article/details/7572964
Saveorupdate (): Can be above the picture here in a word. a deeper understanding is that Java object-oriented is all aspects .
Temporary object, that is, not in the session, there is no persistent identity, the database has no corresponding record of this data, at this time to use save;
Persistent object, in the session, has persistent identity OID, at this time the contents of the data as long as the modification, (ID) can not be changed, will cause the data this object and database linkage,
This is done by hibernate through synchronization. Specifically how to achieve, can refer to the life cycle of objects, and garbage collection has a trace of the relationship. The data at this point can be modified even if you do not use Saveorupdate to update the database.
There is also an object: a de-tube object. This object has a persistent identity, which means that the database has the corresponding data record, but the session is closed, that is, the session cache does not have this object. Not subject to the management of the session. If you modify the properties of this object, there will be no linkage,
That is, the data is not reflected in the database, unless the Saveorupdate () method is called, and after commit, the object becomes a persisted object.
Hibernate in Saveorupdate (), Save (), update (), merge () What do you think of it;