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?
|