Session s = openSession(); s.beginTransaction(); Set parents = new HashSet(); for (int i=0; i<5; i++) { Parent p = new Parent( String.valueOf( i ) ); Child child = new Child( "child" + i ); child.setParent( p ); p.getChildren().add( child ); s.save( p ); parents.add(p); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); int i = 0; for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) { Parent p = (Parent) it.next(); assertEquals( 1, p.getChildren().size() ); i++; if (i % 2 == 0) { s.flush(); s.clear(); } } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); for (Iterator it=parents.iterator(); it.hasNext(); ) { s.delete(it.next()); } s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); Set parents = new HashSet(); for (int i=0; i<5; i++) { Parent p = new Parent( String.valueOf( i + 100 ) ); Child child = new Child( "child" + i ); child.setParent( p ); p.getChildren().add( child ); s.save( p ); parents.add(p); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); Parent p = null; for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) { if ( p != null) { s.evict(p); } p = (Parent) it.next(); assertEquals( 1, p.getChildren().size() ); } s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); for (Iterator it=parents.iterator(); it.hasNext(); ) { s.delete(it.next()); } s.getTransaction().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/reattachment/ProxyReattachmentTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/reattachment/ProxyReattachmentTest.java
Method name: void testIterateWithClearBottomOfLoop() Method name: void testIterateWithEvictTopOfLoop()
Number of AST nodes: 30 Number of AST nodes: 28
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		Set parents = new HashSet();
3
		Set parents = new HashSet();
4
		for (int i=0; i<5; i++) {
4
		for (int i=0; i<5; i++) {
5
			Parent p = new Parent( String.valueOf( i ) );
5
			Parent p = new Parent( String.valueOf( i + 100 ) );
6
			Child child = new Child( "child" + i );
6
			Child child = new Child( "child" + i );
7
			child.setParent( p );
7
			child.setParent( p );
8
			p.getChildren().add( child );
8
			p.getChildren().add( child );
9
			s.save( p );
9
			s.save( p );
10
			parents.add(p);
10
			parents.add(p);
11
		}
11
		}
12
		s.getTransaction().commit();
12
		s.getTransaction().commit();
13
		s.close();
13
		s.close();
14
		s = openSession();
14
		s = openSession();
15
		s.beginTransaction();
15
		s.beginTransaction();
16
		int i = 0;
16
		Parent p = null;
17
		for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
17
		for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
18
			Parent 
18
			if ( p != null) { s.evict(p); }
19
p = (Parent) it.next();
19
			p = (Parent) it.next();
20
			assertEquals( 1, p.getChildren().size() );
20
			assertEquals( 1, p.getChildren().size() );
21
			i++;
21
		
22
			if (i % 2 == 0) {
23
				s.flush();
24
				s.clear();
25
			}
26
		}
22
}
27
		s.getTransaction().commit();
23
		s.getTransaction().commit();
28
		s.close();
24
		s.close();
29
		s = openSession();
25
		s = openSession();
30
		s.beginTransaction();
26
		s.beginTransaction();
31
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
27
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
32
			s.delete(it.next());
28
			s.delete(it.next());
33
		}
29
		}
34
		s.getTransaction().commit();
30
		s.getTransaction().commit();
35
		s.close();
31
		s.close();
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.1
Clones locationClones are declared in the same class
Number of node comparisons1