public void testFetchInitializedCollection() throws Exception { Session s = openSession(); Baz baz = new Baz(); Collection fooBag = new ArrayList(); fooBag.add( new Foo() ); fooBag.add( new Foo() ); baz.setFooBag(fooBag); s.save(baz); s.flush(); fooBag = baz.getFooBag(); s.find("from Baz baz left join fetch baz.fooBag"); assertTrue( fooBag==baz.getFooBag() ); s.connection().commit(); s.close(); s = openSession(); baz = (Baz) s.load( Baz.class, baz.getCode() ); Object bag = baz.getFooBag(); assertFalse( Hibernate.isInitialized(bag) ); s.find("from Baz baz left join fetch baz.fooBag"); assertTrue( bag==baz.getFooBag() ); assertTrue( baz.getFooBag().size()==2 ); s.delete(baz); s.flush(); s.connection().commit(); s.close();
public void testCollectionRefresh() throws Exception { Session s = openSession(); Category c = new Category(); List list = new ArrayList(); c.setSubcategories(list); list.add( new Category() ); c.setName("root"); Serializable id = s.save(c); s.flush(); s.connection().commit(); s.close(); s = openSession(); c = (Category) s.load(Category.class, id); s.refresh(c); s.flush(); assertTrue( c.getSubcategories().size()==1 ); s.flush(); s.connection().commit(); s.close(); s = openSession(); c = (Category) s.load(Category.class, id); assertTrue( c.getSubcategories().size()==1 ); s.delete(c); s.flush(); s.connection().commit(); s.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/MasterDetailTest.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
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
	
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0