aspose file tools*
The moose likes Object Relational Mapping and the fly likes In JPA OneToOne relationship how to  insert only one side of the relation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "In JPA OneToOne relationship how to  insert only one side of the relation " Watch "In JPA OneToOne relationship how to  insert only one side of the relation " New topic
Author

In JPA OneToOne relationship how to insert only one side of the relation

Jones Gold
Greenhorn

Joined: Mar 25, 2013
Posts: 1

Hi friends
I want to insert data in one side of the relation

This is my Parent entity





This is my Child entity




Remote Interface Implementation





This is My Insertion Class Save method



When I call Save matheod
MY DATABASE SHOWING RESULT AS
Parent Table In this is primary key

id pfirstName parentAge plastName
1 GOL 1 JON

Child Table
In this Child Table ID is primary key and pid is foreign key which refers to Parent Table Id
id cfirstName childtAge clastName pid
1 jj 1 gg 1

Now I Want to insert only Child Table like below
id cfirstName childtAge clastName pid
1 jj 1 gg 1
2 kk 2 oo 1

How it possible?


James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
I assume you want to insert another child of the same parent.

Since the parent is existing, you should first find() the existing parent, then create a new Child with that parent and persist it.

If you are dealing with a detached child (serialize from remote), then you can call merge() instead of persist, and JPA should figure out it is new and the parent is existing (assuming the id is set in the parent).

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
 
subject: In JPA OneToOne relationship how to insert only one side of the relation