Two entities: Item, SubItem
Quote:
Item has an:
Id: int
Code: string
subitems: Collection<SubItem>
SubItem has:
Parent: Item
Item: Item
Quantity: float
Situation: Batch inserts
Quote:
item = new Item
item.Code = "1"
item2 = new Item
item2.Code = "2"
item3 = new Item
item3.Code = "3"
item4 = new Item
item4.Code = "4"
item.Add(new SubItem(item2, 50));
item.Add(new SubItem(item3, 50));
item4.Add(new SubItem(item2, 50));
item4.Add(new SubItem(item3, 50));
--> Batch insert processing
Quote:
openSession()
saveOrUpdate(item);
**** INSERT INTO ITEMS(ID, CODE) VALUES (1, "1");
****** INSERT INTO ITEMS(ID, CODE) VALUES (2, "2");
****** INSERT INTO ITEMS(ID, CODE) VALUES (3, "3");
****** INSERT INTO SUBITEMS(ID, PARENT_ID, ITEM_ID, QUANTITY) VALUES (1, 1, 2, 50);
****** INSERT INTO SUBITEMS(ID, PARENT_ID, ITEM_ID, QUANTITY) VALUES (2, 1, 3, 50);
saveOrUpdate(item4);
**** INSERT INTO ITEMS(ID, CODE) VALUES (4, "4");
****** INSERT INTO ITEMS(ID, CODE) VALUES (5, "2"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This insert is wrong, the Item2 has inserted previously with ID=2.
****** INSERT INTO ITEMS(ID, CODE) VALUES (6, "3"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This insert is wrong, the Item3 has inserted previously with ID=3.
****** INSERT INTO SUBITEMS(ID, PARENT_ID, ITEM_ID, QUANTITY) VALUES (3, 4, 5, 50); <<<<<<<< Should be: VALUES (1, 4, 2, 50);
****** INSERT INTO SUBITEMS(ID, PARENT_ID, ITEM_ID, QUANTITY) VALUES (4, 4, 6, 50); <<<<<<<< Should be: VALUES (1, 4, 3, 50);
closeSession()
How Can I solve that?
Second level cache?