• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Does Cascade anototation is equivalent to Cascading in db schema ?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pramma Moorthy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey James, thanks. that was helpful.
Hi Arun. thanks for reminding me.
    Bookmark Topic Watch Topic
  • New Topic