Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JPA - child insertion while parent updation is possible?

 
Greenhorn
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I've a usual scenario where parent has @OneToMany uni-directional relationship with child. And I specified the cascade type = ALL. So whenever I insert the parent its child recored also gets inserted and whenever I updated the parent the child recored also gets updated.

Is it possible to insert a set of new child records while updating the parent record?
And also is it possible to delete the child record while updating the parent record?

Thanks in advance
Vijay
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Murali Vijay
Greenhorn
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Is it possible to insert a set of new child records while updating the parent record?
Sorry for this question, I tried and works fine. Yes its possible to insert a new child record while updating the parent record.

2. Is it possible to delete the child record while updating the parent record?
we've 3 tables as below
1. Parent
2. Child
3. Parent_Child

If I delete the child record while updating the parent the mapping in the table 'Parent_Child' alone gets deleted. But the child data in table 'Child' still exist.
In my scenario I want to delete the child record too.
 
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If I delete the child record while updating the parent the mapping in the table 'Parent_Child' alone gets deleted. But the child data in table 'Child' still exist.
In my scenario I want to delete the child record too.



In the earlier versions delete orphan was not supported in JPA (https://coderanch.com/t/218171/ORM/java/all-delete-orphan-JPA).
I am not sure if this has been added in newer releases of JPA
 
Murali Vijay
Greenhorn
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi rancher, thanks for your idea.
Im using JPA 1.0. And orphanRemoval feature is available in JPA 2.0.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic