-->
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: ManyToOne FK column setting
PostPosted: Tue Dec 28, 2010 12:05 pm 
Newbie

Joined: Tue Dec 28, 2010 11:36 am
Posts: 1
Hi, I have a OneToMany relationship between entities Contact and Email. When I create a Contact and add to him 1 or more Email I need to set the FK column in Email table to the right Contact of that email...

I tried this:
Code:
@Entity
class Contact{
     @Id
     ......
    @OneToMany(mappedBy="contact", cascade=CascadeType.ALL)
    private Set<ContactEmail> email;
}

@Entity
class Email{
     @Id
     ......
    @ManyToOne
    @JoinColumn(name="CONTACT_ID")
    private Contact contact;
}


When in my test package I call:

em.persist(contact); //(where contact has 2 emails associated)

it creates 1 contact, 2 emails records but the FK column "CONTACT_ID" is empty...

how can I set its value with rhe right Contact ID of that email?

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.