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();
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(); for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) { Parent p = (Parent) it.next(); assertEquals( 1, p.getChildren().size() ); s.evict(p); } 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 testIterateWithEvictTopOfLoop() Method name: void testIterateWithEvictBottomOfLoop()
Number of AST nodes: 28 Number of AST nodes: 26
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 + 100 ) );
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
		Parent p = null;
16
		
17
		for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
17
for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
18
			if ( p != null) { s.evict(p); }
18
			
19
			p = (Parent) it.next();
19
Parent p = (Parent) it.next();
20
			assertEquals( 1, p.getChildren().size() );
20
			assertEquals( 1, p.getChildren().size() );
21
		
21
			s.evict(p);
22
}
22
		}
23
		s.getTransaction().commit();
23
		s.getTransaction().commit();
24
		s.close();
24
		s.close();
25
		s = openSession();
25
		s = openSession();
26
		s.beginTransaction();
26
		s.beginTransaction();
27
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
27
		for (Iterator it=parents.iterator(); it.hasNext(); ) {
28
			s.delete(it.next());
28
			s.delete(it.next());
29
		}
29
		}
30
		s.getTransaction().commit();
30
		s.getTransaction().commit();
31
		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 comparisons3