Cascade Policy: Responsible for controlling the association between the object to the object cascade, including update, delete, and so on, the other objects are also affected, such as I delete an object, then it is a many-to-one relationship of the object is also deleted.
After using the crawl strategy, after interviewing a sub-operation of the note: Cascadetype.merge Way
@OneToOne (Cascade={cascadetype.merge}) @JoinColumn (name= "company_id") Publiccompany Getcompany () {return company;} Publicvoid Setcompany (company company) {this.company= Company;}
Cascadetype.merge Cascade UPDATE, cascade operation is usually to the entity's additions and deletions to the operation, and the crawl strategy reflects the association object, mainly reflected in the above.
In addition, there are several types of cascading:
Cascadetype.refresh: Cascade Refresh, when multiple users operate an entity at the same time, in order to get the data from the user is real-time, before using the data in the entity can call the REFRESH () Method!
Cascadetype.remove: Cascade Delete, when the Remove () method is called, the primary key table is deleted before the foreign key table is deleted!
Cascadetype.merge: Cascading updates
Cascadetype.all: Contains all of the cascading properties above.
The above cascade operations can only be effective if the database constraints are met.
These strategies, annotations are flexible configuration, there are many parameters for us to choose, which type needs to be directly used on it. Very convenient, set which parameters at a glance.
First I declare that this cascade operation is the same as the Cascade operation we have previously understood, except that we are using annotations in this form. Now the difference between this and our previous use is that we were directly against the database, if it is directly targeted at the database is equivalent to writing dead; now with hibernate annotations, it is the relationship between object and object, object-oriented, more flexible. If it is an object operation then our entity must be flexible, do not write dead, write dead feeling and the same way as the previous database.
Although the cascade operation is convenient for us to manipulate the data, we cannot rely on it, and if the amount of data is particularly large or many-to-many relationships, the cascade will be slow.
"Hibernate learning"-Cascade operations