As Code,s.email Asemail,s.entrancedate as Entrancedate,s.graduateschool Asgraduateschool,s.identitycardid as Identitycardid,s.classes.classname Asclassname,s.classes.institution.institutionname AsinstitutionName, S.classes.institution.parentinstitution.institutionname Asparentinstitution, S.classes.institution.schoollevel.levelname Aslevelname,s.classes.institution.id as InstitutionId, S.professional.professionalcodeas professionalcode) from Student S where S.isdelete =:isdeleteWhen you print t
field:
mysql> ALTER TABLE table_name DROP field_name;
Cascade update and delete (red, Case Insensitive)
DROP TABLE IF EXISTS `mail_model`;create table mail_model(id varchar(50) primary key not null ,mail_filename varchar(200),content varchar(2000))ENGINE=InnoDB DEFAULT CHARSET=gbk;
DROP TABLE IF EXISTS `mail_model_extend`;create table mail_model_extend(id int(6) auto_increment not null primary key,rid varchar(50) not null,content varchar(2000),INDEX
Mysql implements cascade operations (cascade update and cascade deletion) and mysql implements
1. Create two tables stu, SC
Create table stu (sid int UNSIGNED primary key auto_increment, name varchar (20) not null) TYPE = InnoDB charset = utf8; create table SC (scid int UNSIGNED primary key auto_increment, sid int UNSIGNED not null, score varchar (20) default '0'
= new staff (); Staff.setname ( "www" //add Department staff.setdept (dept) to staff; //add staff to department dept.getstaffset (). add (staff); //save Department session.save (dept); //save employee session.save (staff); As a result, two instances are definitely saved to the corresponding Table. When we do not know anything, we will save the department, and then save the staff, so that two records into the response table
, if the use of cascading, then it is not necessary to write such a trouble.For example, when we want to save the staff, we also save the dept in passing.Other unchanged, add cascading properties in Staff.hbm.xmlCascade= "Save-update" is set in the associated property here to indicate that the entity class object will be associated with the object if it is in save or update or saveorupdate operation (if there is a value for this object, that is, the Reference object variable)The corresponding op
relationship. In general, in a two-way one-to-many relationship, the "many" end, is generally the maintenance side of the Relationship. @Entity@Table (name = "student")public class Student {@Id@GeneratedValue (strategy = generationtype.auto)Private Long id;//establish foreign key "school_fk" in the table@ManyToOne@JoinColumn (name= "school_fk")Private School School;//omit several get/set}@Entity@Table (name = "school")public class School {@Id@GeneratedValue (strategy = generationtype.auto)Priva
studentinfo;
1.2 The second annotation is based on the JPA specification, that is, the Apache jsr220 specification, which is also the persistent layer specification of ejb3.
Javax. Persistence. cascadetype
All,
Persist: Calls session. persist () to trigger merge. Calls session. Merge () to triggerRemove, triggered by calling session. Delete ()Refresh, detach
Configuration example
Java code
@ Manytoone (cascade = {cascadetype. Merge })
@ Joincol
list of SQL to know that performance is low, you have not changed the association table also send you an UPDATE statement, I never use this property.Cascadetype.delete: When calling Session.delete (A), cascade deletes the associated object. (Note: Call A.SETB (NULL) First and then call Session.delete (A) so that cascade does not remove the B.Cascadetype.delete_orphan: A pair of
[Mysql] the disadvantage of external key cascade and cascade, mysql key-level disadvantage
When creating a table, you can set delete and update to cascade. An example is used to describe the concept of cascade of Foreign keys.
Assume that a usertable exists in the database as follows:
This user table is very simple an
Oracle foreign key cascade deletion and cascade updateCascading Deletion
Oracle has three behaviors: no action (similar to RESTRICT), CASCADE, and set null.
The following uses the student-class as an example to describe how to delete Foreign keys in different situations. A student belongs to a class and the primary key of the class is the foreign key of the stude
Oracle foreign key cascade deletion and cascade update, oracle key level update
Cascading Deletion
Oracle has three behaviors: no action (similar to RESTRICT), CASCADE, and set null.
The following uses the student-class as an example to describe how to delete Foreign keys in different situations. A student belongs to a class and the primary key of the class is t
: Department.hbm.xmlAs you can see, in the set tag above, we define the cascade= "Save-update" property, when the session saves or updates the object by using Save (), update (), Saveorupdate () method. Cascade saves all associated new temporary objects, and cascade updates all associated free objectsLet's write a test
void cascade (){Session session = hibernateuitl. getsessionfactory (). opensession ();User u = new user ();Group G = new group ();G. setname ("G ");U. setname ("AA ");Session. begintransaction ();Session. Save (g); // This group exists firstU. setgroup (g );Session. Save (U); // Save the studentSession. gettransaction (). Commit ();Session. Close ();}How can we
mapping File: Department.hbm.xmlCan see, in the Set tab above. We define the cascade= "Save-update" attribute, which, when the session is saved or updated by the Save (), update (), Saveorupdate () method, Cascade saves all the newly created temporary objects associated with the object. And the Cascade updates all associated free objectsLet's write a test. Class
When you are building a table, you can set up cascading for deleting delete and modifying update. The concept of a foreign-key cascade Cascade is illustrated with an exampleIf there is a usertable in the database as follows:This user table is very simple and the ID is the primary key.Below I will create a new cascade_test table as follows, where user_id and Usert
Ivate Long ID;
A foreign key "SCHOOL_FK" is established in the table @ManyToOne @JoinColumn (name= "SCHOOL_FK") private school school; Omit several get/set}
@Entity @Table (name = "School") public class School {@Id @GeneratedValue (strategy = Generationtype.auto) Priv Ate Long ID;
@OneToMany (mappedby= "shcool")//settings: Cascading save/new operation. When new schools and students are kept, the newly-bu
with the Table = "student_course"Lazy = "false"Inverse = "false"Cascade = "Save-Update">Add the following to the corresponding course ing file:Table = "student_course"Lazy = "false"Inverse = "true"Cascade = "Save-Update">Add link:First, write a program to see what courses a student named Bill has chosen:// Obtain the student object representing BillStudent Stu = (student) Session. createquery ("from studen
foreign KEY cascade Delete is no action, perform delete class operation.2, SET NULLSet NULL refers to setting the value of the corresponding reference column in the child table to a null value when the data for the referenced column in the primary table is deleted. Set NULL is a precondition that the foreign key reference column must be set to NULL.Change the foreign key deletion behavior of the student table (tb_student) to set NULL. Oracle does not
Label:SQL Cascade UPDATE, cascade Delete did a test today, made clear cascade Update, cascade DeleteCascade Delete: When we do not have a key to cascade Delete, delete the primary key table data (foreign key table has reference data), will be error, cannot delete, must first
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.