user3407459
user3407459

Reputation: 31

save parent in hibernate with child

I am lil bit confused in hibernate,

Here i am having one parent object and this parent object (Suppose A is a parent and B is child object) has many to one unidirectional relation with child object B.

Now, I have a object A along with Object B . What i have done is , i saved all the child objects in database, so now every child objects are saved in db and have id .

Now i want to save parent object A for its related child object. How can i do that ? Though it might be very simple for u guys, i am new to hibernate. so need lil help.

Thanx in advance. :)

Upvotes: 0

Views: 1445

Answers (1)

HJK
HJK

Reputation: 1382

Why are you saving parent and child separately? Set the child to parent and merge the parent. Underlying ORM technology will take care of rest. But just add cascade type PERSIST and MERGE (ideally PERSIST is enough, but MERGE handles updates as well) over the relationship in parent entity.

Upvotes: 1

Related Questions