One-to-multiple bidirectional cascading deletion of Hibernate

Source: Internet
Author: User

Package pojo;
Public class operator {
Private int ID;
Private string name;
Private string password;
Private roleinfo role;
Private int PID;
Private int rootid;
Private string createip;
Private string createtime;
Private string updatetime;
Private string messagecentertype;
Private string status;
Private string local;
Public String getlocal (){
Return local;
}
Public void setlocal (string local ){
This. Local = local;
}
Public String getstatus (){
Return status;
}
Public void setstatus (string status ){
This. Status = status;
}
Public String getcreateip (){
Return createip;
}
Public void setcreateip (string createip ){
This. createip = createip;
}
 
 
Public String getmessagecentertype (){
Return messagecentertype;
}
Public void setmessagecentertype (string messagecentertype ){
Messagecentertype = messagecentertype;
}
Public String getname (){
Return name;
}
Public void setname (string name ){
This. Name = Name;
}
Public String GetPassword (){
Return password;
}
Public void setpassword (string password ){
This. Password = password;
}
 
Public int GETID (){
Return ID;
}
Public void setid (int id ){
This. ID = ID;
}
Public int getpid (){
Return PID;
}
Public void setpid (int pid ){
This. PID = PID;
}
 
Public roleinfo getrole (){
Return role;
}
Public void setrole (roleinfo role ){
This. Role = role;
}
Public int getrootid (){
Return rootid;
}
Public void setrootid (INT rootid ){
This. rootid = rootid;
}
Public String getcreatetime (){
Return createtime;
}
Public void setcreatetime (string createtime ){
This. createtime = createtime;
}
Public String getupdatetime (){
Return updatetime;
}
Public void setupdatetime (string updatetime ){
This. updatetime = updatetime;
}
 
}

 

<! Doctype hibernate-mapping public
"-// Hibernate/hibernate mapping DTD 3.0 // en"
Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>

<Hibernate-mapping>
<Class
Name = "pojo. Operator"
Table = "operatorinfo"
Lazy = "false"
>
<ID
Name = "ID"
Type = "integer"
Column = "operatorid"
Length = "10"
>
<Generator class = "increment"> </generator>
</ID>

<Property
Name = "name"
Type = "string"
Column = "operatorname"
Length = "20"
/>
<Property
Name = "password"
Type = "string"
Column = "password"
Length = "20"
/>
<Property
Name = "createtime"
Type = "string"
Column = "createtime"
Length = "50"
/>
<Property
Name = "updatetime"
Type = "string"
Column = "updatetime"
Length = "50"
/>
<Property
Name = "local"
Type = "string"
Column = "local"
Length = "100"
/>
<Property name = "PID"
Column = "PID"
Type = "integer"
Length = "10">
</Property>
 
<Property name = "rootid"
Column = "rootid"
Type = "integer"
Length = "10">
</Property>
 
<Property name = "messagecentertype"
Column = "messagecentertype"
Type = "string"
Length = "20">
</Property>
<Property name = "status"
Column = "status"
Type = "string"
Length = "4">
</Property>
<Property name = "createip"
Column = "createip"
Type = "string"
Length = "100">
</Property>
 
<Role-to-one name = "role"
Column = "roleid"
 
Cascade = "all"
Class = "pojo. roleinfo"
 
>

</Role-to-one>
<! -- Associations -->

</Class>
</Hibernate-mapping>

 

Package pojo;

Import java. util. Set;

Public class roleinfo {
Private int ID;
Private string rolename;
Private string roledesc;
Private set <module> modules;
Private set <operator> operators;
Public set <operator> getoperators (){
Return operators;
}
Public void setoperators (set <operator> operators ){
This. Operators = operators;
}
Public set <module> getmodules (){
Return modules;
}
Public void setmodules (set <module> modules ){
This. Modules = modules;
}
Public String getroledesc (){
Return roledesc;
}
Public void setroledesc (string roledesc ){
This. roledesc = roledesc;
}
Public String getrolename (){
Return rolename;
}
Public void setrolename (string rolename ){
This. rolename = rolename;
}
Public int GETID (){
Return ID;
}
Public void setid (int id ){
This. ID = ID;
}

 
}

 

<? XML version = "1.0"?>
<! Doctype hibernate-mapping public
"-// Hibernate/hibernate mapping DTD 3.0 // en"
Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>
<Hibernate-mapping>
<Class
Name = "pojo. roleinfo"
Table = "roleinfo"
Lazy = "false"
Dynamic-insert = "true"
Dynamic-update = "true"
>
<ID
Name = "ID"
Type = "integer"
Column = "roleid"
Length = "10"
Unsaved-value = "0"
>
<Generator class = "increment"/>
</ID>
<Property
Name = "rolename"
Type = "string"
Column = "rolename"
Length = "20"
/>

<Property
Name = "roledesc"
Type = "string"
Column = "roledesc"
Length = "4000"
/>
<Set name = "modules"
Table = "role2module"
Inverse = "false"
Lazy = "false"
Cascade = "all">
<Key column = "roleid"> </key>
<Skip-to-skip class = "pojo. Module"
Column = "moduleid" outer-join = "Auto">
</Upload-to-sequence>
</Set>
<Set name = "operators"
Table = "operatorinfo"
Inverse = "true"
Cascade = "all"
Lazy = "false"
>
<Key column = "roleid"> </key>
<One-to-least
Class = "pojo. Operator"
/>
</Set>
</Class>
</Hibernate-mapping>

 

 

 

Public String deleterole (string [] IDs ){
String S = "0 ";
Session session = super. getsession (true );
Try {
For (INT I = 0; I <IDs. length; I ++ ){
// Session. Delete (findbyid (integer. parseint (IDs [I]);
/**
* Session. Get (Class class, int ID)
*/
Roleinfo role = (roleinfo) Session. Get (roleinfo. Class, integer. parseint (IDs [I]);
Set <operator> set = role. getoperators ();
For (iterator iter = set. iterator (); ITER. hasnext ();){
Operator O = (operator) ITER. Next ();
Session. Delete (O );
Role. getoperators (). Remove (O );
Role. getoperators (). Clear ();
// Role. getoperators (). Remove (O );
}

// Role. getoperators (). Clear ();
Session. Delete (role );

}
S = "1 ";
} Catch (exception e ){

}


Return S;
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.