wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes How to add a new OneToMany Child To a given Parent in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to add a new OneToMany Child To a given Parent in JPA" Watch "How to add a new OneToMany Child To a given Parent in JPA" New topic
Author

How to add a new OneToMany Child To a given Parent in JPA

Asme Williams
Greenhorn

Joined: Feb 26, 2013
Posts: 16
I have two to entity Parent and Child and I want add a new child for a given parent: here is what I tried but the Child object is not persisted in the database.

Parent Entity


Child Entity



Servlet


Well, I just don't know how to do it, but I've made some search and this is what I tried so far
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You need to call persist on both the parent and the child, or set cascade persist in the OneToMany.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Asme Williams
Greenhorn

Joined: Feb 26, 2013
Posts: 16
Well I have tryed both but the children is not persisted in the database:

I have try to persist the child by adding this methode childDao.addChild(newChild);.

I have try to add the cascade=CascadeType.PERSIST to the OneToMany (the Parent) side too but it dont work.
Asme Williams
Greenhorn

Joined: Feb 26, 2013
Posts: 16
I've finally Solve the problem,

I've foregetted to add the second "@EJB" notification


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add a new OneToMany Child To a given Parent in JPA
 
Similar Threads
hibernat creating the tables without cascade
two parents, one child, ora-02291
JPA data retrieval query
one to many mapping(unidirection)
Column index not populated?