File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Does Cascade anototation is equivalent to Cascading in db schema ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Does Cascade anototation is equivalent to Cascading in db schema ?" Watch "Does Cascade anototation is equivalent to Cascading in db schema ?" New topic
Author

Does Cascade anototation is equivalent to Cascading in db schema ?

Pramma Moorthy
Greenhorn

Joined: Jul 16, 2009
Posts: 2
When i annotate an element as say '@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)',
is that equivalent to cascade in db schema itself?

or to be precise, after creating such entity in db, if i execute a 'delete' query in db on primary entity, will it perform cascade delete?
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
No, not really.

cascade will not cause the database constraint to be created with cascade delete (but may be JPA provider dependent).
It only affects when the parent object is removed through JPA.

You can create your constraint with cascade delete if you desire, using your own DDL scripts. Some JPA providers support generating the cascade delete on the constraint if using their DDL generation support.
The latest builds of EclipseLink provide a @CascadeOnDelete annotation for this.

Note that cascade delete only applies to a constraint, and only works in the inverse direction of the constraint. Where as JPA cascade works in the direction of the relationship, on any relationship type. So a cascade delete in your database will only work if the constraint for your OneToOne is from the dependent object back to the parent object. If your OneToOne uses a JoinColumn, then a cascade delete in the database will not work.



TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Hi "Always Curious",
Welcome to javaranch. We are happy to help you, but at the same time we have some strict but friendly rules.
Please find our Naming Policy.
You can change your name here.


If you are not laughing at yourself, then you just didn't get the joke.
Pramma Moorthy
Greenhorn

Joined: Jul 16, 2009
Posts: 2
Hey James, thanks. that was helpful.
Hi Arun. thanks for reminding me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does Cascade anototation is equivalent to Cascading in db schema ?