Session s = openSession(); Transaction t = s.beginTransaction(); Person p = new Person(); p.setName( "Steve" ); p.setUserId( "steve" ); s.persist( p ); Group g = new Group(); g.setName( "Admins" ); g.getUsers().add( p ); s.persist( g ); // force a flush and detachment here to test reattachment handling of the property-ref (HHH-1531) t.commit(); s.close(); Person p2 = new Person(); p2.setName( "Max" ); p2.setUserId( "max" ); g.getUsers().add( p2 ); s = openSession(); t = s.beginTransaction(); s.update( g ); t.commit(); s.close(); // test retrieval of the group s = openSession(); t = s.beginTransaction(); g = ( Group ) s.createQuery( "from Group g left join fetch g.users" ).uniqueResult(); assertTrue( Hibernate.isInitialized( g.getUsers() ) ); assertEquals( 2, g.getUsers().size() ); s.delete( g ); s.createQuery( "delete Person" ).executeUpdate(); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); User u = new User("max"); u.getEmailAddresses().add( new Email("max@hibernate.org") ); u.getEmailAddresses().add( new Email("max.andersen@jboss.com") ); s.persist(u); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); User u2 = (User) s.createCriteria(User.class).uniqueResult(); assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); assertEquals( u2.getEmailAddresses().size(), 2 ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); u2 = ( User ) s.get( User.class, u.getUserName() ); u2.getEmailAddresses().size(); assertEquals( 2, MyListType.lastInstantiationRequest ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); s.delete( u ); t.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/propertyref/basic/PropertyRefTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java
Method name: void testManyToManyPropertyRef() Method name: void testBasicOperation()
Number of AST nodes: 30 Number of AST nodes: 27
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		Person p = new Person();
3
		User u = new User("max");
4
		p.setName( "Steve" );
4
		
5
		p.setUserId( "steve" );
6
		s.persist( p );
7
		Group g = new Group();
8
		g.setName( "Admins" );
5
u.getEmailAddresses().add( new Email("max@hibernate.org") );
9
		g.getUsers().add( p );
6
		u.getEmailAddresses().add( 
10
		s.persist( g );
11
		// force a flush and detachment here to test reattachment handling of the property-ref (HHH-1531)
7
new Email("max.andersen@jboss.com") );
8
		s.persist(u);
12
		t.commit();
9
		t.commit();
13
		s.close();
10
		s.close();
14
		Person p2 = new Pers
11
		
15
on();
12
		s = openSession();
16
		p2.setName( "Max" );
13
		t = s.beginTransaction();
17
		p2.setUserId( "max" );
14
		
18
		g.getUsers().add( p2 );
19
		s = openSession();
20
		t = s.beginTransaction();
21
		s.update( g
15
User u2 = (User) s.createCriteria(User.class).uniqueResult();
16
		assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
22
 );
17
		assertEquals( u2.getEmailAddresses().size(), 2 );
23
		t.commit();
18
		t.commit();
24
		s.close();
19
		s.close();
25
		// test retrieval of the group
26
		s = openSession();
20
		s = openSession();
27
		t = s.beginTransaction();
21
		t = s.beginTransaction();
28
		g = ( Group ) s.createQuery( "from Group g left join fetch g.users" ).uniqueResult();
22
		u2 = ( 
29
		assertTrue( Hibernate.isInitialized( g.getUsers() ) );
30
		assertEquals( 2, g.getUsers().size() 
23
User ) s.get( User.class, u.getUserName() );
24
		u2.getEmailAddresses().size();
25
		assertEquals( 2, MyListType.lastInstantiationRequest );
31
);
26
		t.commit();
32
		s.delete( g );
27
		s.close();
33
		s.createQuery( "delete Person" ).executeUpdate(
28
		s = openSession();
29
		t = s.beginTransaction();
34
);
30
		s.delete( u );
35
		t.commit();
31
		t.commit();
36
		s.close();
32
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are in different classes having the same super class
Number of node comparisons380
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements16
    Number of unmapped statements in the first code fragment14
    Number of unmapped statements in the second code fragment11
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    Session s = openSession();
    1
    Session s = openSession();
    2
    Transaction t = s.beginTransaction();
    2
    Transaction t = s.beginTransaction();
                                                        
    3
    User u = new User("max");
    Preondition Violations
    Unmatched statement User u=new User("max"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    User u = new User("max");
    3
    Person p = new Person();
                                                      
                                                                                                                              
    4
    u.getEmailAddresses().add(new Email("max@hibernate.org"));
    4
    p.setName("Steve");
    4
    p.setName("Steve");
    Preondition Violations
    Unmatched statement p.setName("Steve"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                
                                                                                                                                        
    5
    u.getEmailAddresses().add(new Email("max.andersen@jboss.com"));
    5
    p.setUserId("steve");
    5
    p.setUserId("steve");
    Preondition Violations
    Unmatched statement p.setUserId("steve"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                    
    6
    s.persist(p);
    6
    s.persist(p);
    Preondition Violations
    Unmatched statement s.persist(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                    
    7
    Group g = new Group();
                                                  
                              
    8
    s.close();
    Preondition Violations
    Unmatched statement s.close(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    s.close();
    8
    g.setName("Admins");
    8
    g.setName("Admins");
    Preondition Violations
    Unmatched statement g.setName("Admins"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                  
    9
    g.getUsers().add(p);
                                                  
    10
    s.persist(g);
    10
    s.persist(g);
    6
    s.persist(u);
    Differences
    Expression1Expression2Difference
    guVARIABLE_NAME_MISMATCH
    org.hibernate.test.propertyref.basic.Grouporg.hibernate.test.usercollection.basic.UserVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.propertyref.basic.Group of variable g does not match with type org.hibernate.test.usercollection.basic.User of variable u
    • Make classes org.hibernate.test.propertyref.basic.Group and org.hibernate.test.usercollection.basic.User extend a common superclass
    6
    s.persist(u);
    11
    t.commit();
    7
    t.commit();
                                          
    9
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    s = openSession();
                                                          
    10
    t = s.beginTransaction();
    Preondition Violations
    Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10
    t = s.beginTransaction();
                                                                                                                                
    11
    User u2 = (User)s.createCriteria(User.class).uniqueResult();
    12
    s.close();
    15
    s.close();
    13
    Person p2 = new Person();
                                                          
    14
    p2.setName("Max");
    14
    p2.setName("Max");
    Preondition Violations
    Unmatched statement p2.setName("Max"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                
    15
    p2.setUserId("max");
    15
    p2.setUserId("max");
    Preondition Violations
    Unmatched statement p2.setUserId("max"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                    
    16
    g.getUsers().add(p2);
                                                      
    17
    s = openSession();
    16
    s = openSession();
    18
    t = s.beginTransaction();
    17
    t = s.beginTransaction();
    19
    s.update(g);
    19
    s.update(g);
    Preondition Violations
    Unmatched statement s.update(g); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                    
    20
    t.commit();
    14
    t.commit();
    21
    s.close();
    22
    s.close();
    22
    s = openSession();
    23
    s = openSession();
    23
    t = s.beginTransaction();
    24
    t = s.beginTransaction();
    24
    g = (Group)s.createQuery("from Group g left join fetch g.users").uniqueResult();
    24
    g = (Group)s.createQuery("from Group g left join fetch g.users").uniqueResult();
    Preondition Violations
    Unmatched statement g=(Group)s.createQuery("from Group g left join fetch g.users").uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                        
    25
    assertTrue(Hibernate.isInitialized(g.getUsers()));
    25
    assertTrue(Hibernate.isInitialized(g.getUsers()));
    13
    assertEquals(u2.getEmailAddresses().size(), 2);
    Differences
    Expression1Expression2Difference
    assertTrueassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertTrue(Hibernate.isInitialized(g.getUsers()))assertEquals(u2.getEmailAddresses().size(),2)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue(Hibernate.isInitialized(g.getUsers())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(u2.getEmailAddresses().size(),2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(u2.getEmailAddresses().size(),2) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(g.getUsers())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(u2.getEmailAddresses().size(),2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(u2.getEmailAddresses().size(),2) is a void method call, and thus it cannot be parameterized
    13
    assertEquals(u2.getEmailAddresses().size(), 2);
    26
    assertEquals(2, g.getUsers().size());
    26
    assertEquals(2, g.getUsers().size());
    12
    assertTrue(Hibernate.isInitialized(u2.getEmailAddresses()));
    Differences
    Expression1Expression2Difference
    assertEqualsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(2,g.getUsers().size())assertTrue(Hibernate.isInitialized(u2.getEmailAddresses()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(2,g.getUsers().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,g.getUsers().size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(2,g.getUsers().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,g.getUsers().size()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) is a void method call, and thus it cannot be parameterized
    12
    assertTrue(Hibernate.isInitialized(u2.getEmailAddresses()));
                                                                                                  
    18
    u2 = (User)s.get(User.class, u.getUserName());
    Preondition Violations
    Unmatched statement u2=(User)s.get(User.class,u.getUserName()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18
    u2 = (User)s.get(User.class, u.getUserName());
                                                                        
    19
    u2.getEmailAddresses().size();
                                                                                                                    
    20
    assertEquals(2, MyListType.lastInstantiationRequest);
    27
    s.delete(g);
    27
    s.delete(g);
    25
    s.delete(u);
    Differences
    Expression1Expression2Difference
    guVARIABLE_NAME_MISMATCH
    org.hibernate.test.propertyref.basic.Grouporg.hibernate.test.usercollection.basic.UserVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.propertyref.basic.Group of variable g does not match with type org.hibernate.test.usercollection.basic.User of variable u
    • Make classes org.hibernate.test.propertyref.basic.Group and org.hibernate.test.usercollection.basic.User extend a common superclass
    25
    s.delete(u);
    28
    s.createQuery("delete Person").executeUpdate();
    28
    s.createQuery("delete Person").executeUpdate();
    Preondition Violations
    Unmatched statement s.createQuery("delete Person").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                          
    29
    t.commit();
    21
    t.commit();
                                  
    26
    t.commit();
    Preondition Violations
    Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    26
    t.commit();
    30
    s.close();
    27
    s.close();
    Precondition Violations (34)
    Row Violation
    1Unmatched statement User u=new User("max"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement p.setName("Steve"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement p.setUserId("steve"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement s.persist(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement s.close(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement g.setName("Admins"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7Type org.hibernate.test.propertyref.basic.Group of variable g does not match with type org.hibernate.test.usercollection.basic.User of variable u
    8Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement p2.setName("Max"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    11Unmatched statement p2.setUserId("max"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    12Unmatched statement s.update(g); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Unmatched statement g=(Group)s.createQuery("from Group g left join fetch g.users").uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Expression assertTrue(Hibernate.isInitialized(g.getUsers())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression assertEquals(u2.getEmailAddresses().size(),2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    17Expression assertEquals(u2.getEmailAddresses().size(),2) is a void method call, and thus it cannot be parameterized
    18Expression assertTrue(Hibernate.isInitialized(g.getUsers())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression assertEquals(u2.getEmailAddresses().size(),2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    21Expression assertEquals(u2.getEmailAddresses().size(),2) is a void method call, and thus it cannot be parameterized
    22Expression assertEquals(2,g.getUsers().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression assertEquals(2,g.getUsers().size()) is a void method call, and thus it cannot be parameterized
    25Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) is a void method call, and thus it cannot be parameterized
    26Expression assertEquals(2,g.getUsers().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    27Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    28Expression assertEquals(2,g.getUsers().size()) is a void method call, and thus it cannot be parameterized
    29Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) is a void method call, and thus it cannot be parameterized
    30Unmatched statement u2=(User)s.get(User.class,u.getUserName()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    31Type org.hibernate.test.propertyref.basic.Group of variable g does not match with type org.hibernate.test.usercollection.basic.User of variable u
    32Unmatched statement s.createQuery("delete Person").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    33Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    34Clone fragment #1 returns variables s , while Clone fragment #2 returns variables s, t