posted 17 years ago
I got my mistake.
Actually i was doing
session1.save(item1);
session1.close(); // NOTE : After this stmt, item1 will be detatched
Session session2 = .....;
item1.add(bid1); // Note : item1 is detached object
//cascade-save works only for persistent object and not
//detached objects
session2.getTransaction().commit();
session2.close();
Solution 1 : I should have added bid1 to item1 before session1.close();
as item1 is persistent before session1.close();
Solution 2 : I should have loaded item1 using
Item item2 = (Item)session2.get(Item.class,item.getItemId());
//Note now item2 is persistent (attached to a session)
item2.add(bid1);