1 | public void testFetchInitializedCollection() throws Exception {↵ | | 1 | public void testCollectionRefresh() throws Exception {↵
|
2 | Session s = openSession();↵ | | 2 | Session s = openSession();↵
|
3 | Baz baz = new Baz();↵ | | 3 | ↵
|
4 | Collection fooBag = new ArrayList();↵ | | |
|
5 | fooBag.add( new Foo() );↵ | | |
|
6 | fooBag↵ | | 4 | Category c = new Category();↵
|
| | | 5 | List list = new ArrayList();↵
|
| | | 6 | c.setSubcategories(list);↵
|
7 | .add( new Foo() );↵ | | 7 | list.add( new Category() );↵
|
8 | baz.setFooBag(fooBag);↵ | | 8 | c.set↵
|
9 | s.save(baz);↵ | | |
|
10 | s.flush();↵ | | |
|
11 | fooBag = baz.getFooBag();↵ | | |
|
12 | s.find("from Baz baz left join fetch baz.fooBag");↵ | | |
|
13 | assertTrue( fooBag==baz.getFooBag() ↵ | | 9 | Name("root");↵
|
| | | 10 | Serializable id = s.save(c);↵
|
14 | );↵ | | 11 | s.flush();↵
|
15 | s.connection().commit();↵ | | 12 | s.connection().commit();↵
|
16 | s.close();↵ | | 13 | s.close();↵
|
|
17 | s = openSession();↵ | | 14 | s = openSession();↵
|
18 | baz = (Baz) s.load( Baz.class, baz.getCode() );↵ | | 15 | c = (Category) s.load(↵
|
19 | Object bag = baz.getFooBag();↵ | | |
|
20 | assertFalse( Hibernate.isInitialized(bag) );↵ | | |
|
21 | s.find("from Baz baz left join fetch baz.fooBag");↵ | | |
|
22 | assertTrue( bag==baz.getFooBag() ↵ | | 16 | Category.class, id);↵
|
| | | 17 | s.refresh(c);↵
|
| | | 18 | s.flush();↵
|
| | | 19 | assertTrue( c.getSubcategories().size()==1 );↵
|
| | | 20 | s.flush();↵
|
| | | 21 | s.connection().commit();↵
|
| | | 22 | s.close();↵
|
| | | 23 | s = openSession();↵
|
23 | );↵ | | 24 | c = (Category) s.load(Category.class, id);↵
|
24 | assertTrue( baz.getFooBag().size()==2 );↵ | | 25 | assertTrue( c.getSubcategories().size()==1 );↵
|
25 | s.delete(baz);↵ | | 26 | s.delete(c);↵
|
26 | s.flush();↵ | | 27 | s.flush();↵
|
27 | s.connection().commit();↵ | | 28 | s.connection().commit();↵
|
28 | s.close();↵ | | 29 | s.close();↵
|
29 | | | 30 |
|