Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes JPA - child insertion while parent updation is possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA - child insertion while parent updation is possible?" Watch "JPA - child insertion while parent updation is possible?" New topic
Author

JPA - child insertion while parent updation is possible?

Murali Vijay
Greenhorn

Joined: Jan 05, 2011
Posts: 12

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

Joined: Oct 25, 2008
Posts: 2700

What happened when you tried it?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Murali Vijay
Greenhorn

Joined: Jan 05, 2011
Posts: 12

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

Joined: Aug 11, 2010
Posts: 218

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

Joined: Jan 05, 2011
Posts: 12

Hi rancher, thanks for your idea.
Im using JPA 1.0. And orphanRemoval feature is available in JPA 2.0.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA - child insertion while parent updation is possible?