Hi Gul
A lot depends on use case also. it is not always required/useful to
traverse mappings in both directions. Like in your case if you are
sure that you do not want to traverse the relationship from phone ->
person then you can just treat FK of person in phone as a normal
field. first flush the person entity and then flush the phone numbers.
Probably that would save you one query.


Thanks

- rajeev




On Mon, Mar 10, 2008 at 6:53 AM, Gul Onural <[EMAIL PROTECTED]> wrote:
>
>  I have a Person entity. The Person entity has a list of PhoneNumber
>  entities (as shown below).
>  If I want to add a phone number to a person's list of phone numbers,
>  what is the most efficient/recommended
>  way of doing this ?
>
>  For example is it ok to do something like that in PersonEntity:
>
>  PhoneNumberEntity phoneNumber = new PhoneNumberEntity("1234567890");
>  this.getPhoneNumbers.add(phoneNumber);
>  phoneNumber.setPerson(this);
>
>  Is there any other (better or recommended) way of adding a phone number
>  in terms of
>  performance or in terms of other considerations ?
>
>  Thanks,
>
>  Gul
>
>  @Entity
>  public class PersonEntity implements Serializable {
>     @OneToMany
>     private List<PhoneNumberEntity> phoneNumbers;
>     ...
>  }
>

Reply via email to