• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA - child insertion while parent updation is possible?

 
Murali Vijay
Greenhorn
Posts: 12
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • 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 (http://www.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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic