-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to get the different ID in parent and child table?
PostPosted: Fri Jan 09, 2015 5:09 am 
Newbie

Joined: Fri Jan 09, 2015 4:56 am
Posts: 9
hi, guys.
I am trying to map two tables together:

Page has many Positions
One to Many

and all the process work properly (mapping is ok, create a page with one single position is ok), but just one situation that my child table Position always has the same Id with Page when I created a new page.

How to make them differently?


Page page = new page();

Set<Position> positionSet = new HashSet<Position>();

for (int i=1; i<= 5; i++)
{
Position position = new Position();
position.setPage(page);
position.setPosition(i);
positionSet.add(position);

}

page.setPosition(positionSet);
pageDao.addPage(page);


It looks like Hibernate will automatically set same ID in the child table with parent.

The Position table after the processing of One line inserting:

id position page_id
1 a 1
2 b 1
3 c 1
4 d 1
5 e 1
26 a 26

how to make the id not impacted by page_id?


Top
 Profile  
 
 Post subject: Re: how to get the different ID in parent and child table?
PostPosted: Sun Jan 11, 2015 12:06 am 
Newbie

Joined: Fri Jan 09, 2015 4:56 am
Posts: 9
up and thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.