Difference between revisions of "EclipseLink/UserGuide/JPA/Advanced JPA Development/Schema Generation/CascadeOnDelete"

From Eclipsepedia

Jump to: navigation, search
m
m
Line 6: Line 6:
 
|api=y
 
|api=y
 
|apis=[http://www.eclipse.org/eclipselink/api/latest/eclipse/persistence/annotations/CascadeOnDelete.html CascadeOnDelete]
 
|apis=[http://www.eclipse.org/eclipselink/api/latest/eclipse/persistence/annotations/CascadeOnDelete.html CascadeOnDelete]
}}
+
}}  
=@CascadeOnDelete=
+
  
--THIS PAGE IS IN PROGRESS --
+
= @CascadeOnDelete  =
 +
 
 +
--THIS PAGE IS IN PROGRESS --  
  
 
ON DELETE CASCADE is a database foreign key constraint option that automatically removes the dependent rows.  
 
ON DELETE CASCADE is a database foreign key constraint option that automatically removes the dependent rows.  
  
Use the <tt>@CascadeOnDelete</tt> annotation or the <tt>cascadeOnDelete</tt> property to specify that a delete operation performed on a database object is cascaded  
+
Use the <tt>@CascadeOnDelete</tt> annotation or the <tt>cascadeOnDelete</tt> property to specify that a delete operation performed on a database object is cascaded on secondary or related tables.  
on secondary or related tables.  
+
  
{| border="1" cellpadding="2"
+
{| cellpadding="2" border="1"
|+ ''CascadeOnDelete''
+
|+ ''CascadeOnDelete''  
|-
+
| '''Performing a CascadeOnDelete on this object...''' ||'''Does this...'''
+
 
|-
 
|-
| Entity|| Defines that secondary or joined inheritance tables should cascade the delete on the database
+
| '''Performing a CascadeOnDelete on this object...'''
 +
| '''Does this...'''
 
|-
 
|-
| OneToOne mapping|| The related object is deleted cascaded on the database. This is only allowed for mappedBy/target-foriegn key OneToOne mappings (because of constraint direction).
+
| Entity
 +
| Defines that secondary or joined inheritance tables should cascade the delete on the database
 
|-
 
|-
|OneToMany mapping || The related objects are deleted cascaded on the database.  
+
| OneToOne mapping  
 +
| The related object is deleted cascaded on the database. This is only allowed for mappedBy/target-foriegn key OneToOne mappings (because of constraint direction).
 
|-
 
|-
|ManyToMany mapping || The join table is deleted cascaded on the database (target objects cannot be cascade even if private because of constraint direction).  
+
| OneToMany mapping  
 +
| The related objects are deleted cascaded on the database.
 
|-
 
|-
|DirectCollection || The direct table is deleted cascaded on the database.  
+
| ManyToMany mapping
 +
| The join table is deleted cascaded on the database (target objects cannot be cascade even if private because of constraint direction).
 
|-
 
|-
|AggregateCollection||The aggregate table is deleted cascaded on the database.
+
| DirectCollection
 +
| The direct table is deleted cascaded on the database.
 +
|-
 +
| AggregateCollection
 +
| The aggregate table is deleted cascaded on the database.
 
|}
 
|}
  
 
+
<br> <source lang="java">
<source lang="java">
+
 
@Target(value={METHOD,FIELD,TYPE})
 
@Target(value={METHOD,FIELD,TYPE})
 
@Retention(value=RUNTIME)
 
@Retention(value=RUNTIME)
 
public @interface CascadeOnDelete
 
public @interface CascadeOnDelete
</source>
+
</source>  
  
 +
<br>
  
= Configuration File =
+
= Configuration File =
In the <tt>orm.xml</tt> descriptor file, specify cascade on delete as follows:
+
<source lang="xml">
+
<entity cascadeOnDelete="true">
+
<one-to-one cascadeOnDelete="true">
+
<one-to-many cascadeOnDelete="true">
+
<many-to-many cascadeOnDelete="true">
+
</source>
+
  
{{EclipseLink_JPA
+
In the <tt>orm.xml</tt> descriptor file, specify cascade on delete as follows:
 +
<pre>&lt;source lang="xml"&gt;
 +
&lt;entity cascadeOnDelete="true"&gt;
 +
&lt;one-to-one cascadeOnDelete="true"&gt;
 +
&lt;one-to-many cascadeOnDelete="true"&gt;
 +
&lt;many-to-many cascadeOnDelete="true"&gt;
 +
&lt;/source&gt;
 +
</pre>
 +
<br> {{EclipseLink_JPA
 
|previous =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation|Schema Generation]]
 
|previous =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation|Schema Generation]]
 
|up      =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation|Schema Generation]]
 
|up      =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation|Schema Generation]]
 
|next =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation/Index|@Index]]
 
|next =[[EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Schema_Generation/Index|@Index]]
 
|version=2.2.0 DRAFT}}
 
|version=2.2.0 DRAFT}}

Revision as of 15:02, 31 January 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug api package icon.png Key API CascadeOnDelete


@CascadeOnDelete

--THIS PAGE IS IN PROGRESS --

ON DELETE CASCADE is a database foreign key constraint option that automatically removes the dependent rows.

Use the @CascadeOnDelete annotation or the cascadeOnDelete property to specify that a delete operation performed on a database object is cascaded on secondary or related tables.

CascadeOnDelete
Performing a CascadeOnDelete on this object... Does this...
Entity Defines that secondary or joined inheritance tables should cascade the delete on the database
OneToOne mapping The related object is deleted cascaded on the database. This is only allowed for mappedBy/target-foriegn key OneToOne mappings (because of constraint direction).
OneToMany mapping The related objects are deleted cascaded on the database.
ManyToMany mapping The join table is deleted cascaded on the database (target objects cannot be cascade even if private because of constraint direction).
DirectCollection The direct table is deleted cascaded on the database.
AggregateCollection The aggregate table is deleted cascaded on the database.

@Target(value={METHOD,FIELD,TYPE})
@Retention(value=RUNTIME)
public @interface CascadeOnDelete


Configuration File

In the orm.xml descriptor file, specify cascade on delete as follows:

<source lang="xml">
<entity cascadeOnDelete="true">
<one-to-one cascadeOnDelete="true">
<one-to-many cascadeOnDelete="true">
<many-to-many cascadeOnDelete="true">
</source>

Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...