-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to add to entity child entities - simple question
PostPosted: Mon Sep 21, 2009 6:00 pm 
Newbie

Joined: Mon Sep 21, 2009 5:34 pm
Posts: 1
I have an Entity with a collection of child Entities:

Code:
@Entity
public class Client{
...

@OneToMany(mappedBy="client",cascade=CascadeType.ALL)
@JoinColumn(name="CLIENT_ID")
public List<CarOrder> getOrders(){
   return orders;
}

...
}


Now I want to create new orders and add it to client entity from java without detaching it.
In my business component I have variable `orders' where I accumulate orders that are being added by user before really adding them to client entity. Finally I want to add all orders entered by user to relationships collection on entity class, but whether I do it this way:

Code:
public void addOrders(){
   client.getOrders().addAll(orders);
}


or this way:

Code:
public void addOrders(){
   client.setOrders(orders);
}


Or some other ways client entity is detached and even calling entityManager.merge(client) doesn't help (entityManager.contains(client) still returns false) - and I want to keep it persisted. What is the best way to add child entitities to to parent entity? Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.