-->
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.  [ 4 posts ] 
Author Message
 Post subject: inserting data into two tables
PostPosted: Thu Aug 30, 2007 4:26 pm 
Newbie

Joined: Tue Aug 28, 2007 2:09 pm
Posts: 9
Hi,

I am using Oracle 9i. I have one to many relationship between two tables employee and roles. I have a JSP form to capture the data for both tables. I wrote two POJO classes representing two tables.

My employee table PK is genertaed automatically. So how can i enter the same key into my role table in same code; because i guees unless we commit the transaction the PK-ID won't be automatically inserted into parent (employee) table and i want to insert that key into child table( role) at the same time.

Thanks


Top
 Profile  
 
 Post subject: Re: inserting data into two tables
PostPosted: Thu Aug 30, 2007 4:43 pm 
Beginner
Beginner

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
You just don't set an id for you role objects and do:
employee.add(role1);employee.add(role2);

Hib will take care of the id for role assuming your mapping is correct, ie something like
Code:
@OneToMany
   @JoinTable(
         name="EMP_ROLE",
         joinColumns={@JoinColumn(name="EMP_ID")...}
   Set<Role>roles


* rate if this helps*


Top
 Profile  
 
 Post subject: Re: inserting data into two tables
PostPosted: Thu Aug 30, 2007 4:54 pm 
Newbie

Joined: Tue Aug 28, 2007 2:09 pm
Posts: 9
but then how shall i write the mapping? i mean to tell to pick up FK (emp_id) for Role from Employee?


Top
 Profile  
 
 Post subject: Re: inserting data into two tables
PostPosted: Thu Aug 30, 2007 5:00 pm 
Beginner
Beginner

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
I suggest you read chapter 6:
http://www.hibernate.org/hib_docs/v3/re ... tions.html

* rate if this helps *

c_java wrote:
but then how shall i write the mapping? i mean to tell to pick up FK (emp_id) for Role from Employee?


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

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.