If a new entity element is added to an uninitialized bag, the bag remains uninitialized. If the session is flushed, then the collection is initialized, the
{code} s = openSession(); + txn = s.beginTransaction(); + item = (Item) s.get( Item.class, item.getId() ); + assertFalse( Hibernate.isInitialized( item.getBagOfItems() ) ); + // Add an element to item.bagOfItems (a bag); it will not initialize the bag. + item.addItemToBag( itemElement ); + assertFalse( Hibernate.isInitialized( item.getBagOfItems() ) ); + s.persist( itemElement ); + s.flush(); + // Now initialize the collection; it will contain the uncommitted itemElement. + Hibernate.initialize( item.getBagOfItems() ); + setRollbackOnlyTx(); {code}
|