Session s = openSession(); Transaction t = s.beginTransaction(); User gavin = new User("gavin", "secret"); User turin = new User("turin", "tiger"); Group g = new Group("developers"); g.getUsers().put("gavin", gavin); g.getUsers().put("turin", turin); s.persist(g); gavin.getSession().put( "foo", new SessionAttribute("foo", "foo bar baz") ); gavin.getSession().put( "bar", new SessionAttribute("bar", "foo bar baz 2") ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); g = (Group) s.get(Group.class, "developers"); gavin = (User) g.getUsers().get("gavin"); turin = (User) g.getUsers().get("turin"); assertFalse( Hibernate.isInitialized( g.getUsers() ) ); g.getUsers().clear(); gavin.getSession().remove("foo"); assertTrue( Hibernate.isInitialized( g.getUsers() ) ); assertTrue( Hibernate.isInitialized( gavin.getSession() ) ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); g = (Group) s.get(Group.class, "developers"); assertTrue( g.getUsers().isEmpty() ); assertFalse( Hibernate.isInitialized( g.getUsers() ) ); gavin = (User) s.get(User.class, "gavin"); assertFalse( gavin.getSession().containsKey("foo") ); assertFalse( Hibernate.isInitialized( gavin.getSession() ) ); s.delete(gavin); s.delete(turin); s.delete(g); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Person p = new Person("Gavin"); Person p2 = new Person("Emmanuel"); Employee e = new Employee(p); new Employment(e, "JBoss"); Employment old = new Employment(e, "IFA"); old.setEndDate( new Date() ); s.persist(p); s.persist(p2); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); p = (Person) s.createQuery("from Person where name='Gavin'").uniqueResult(); //assertFalse( Hibernate.isPropertyInitialized(p, "employee") ); assertSame( p.getEmployee().getPerson(), p ); assertTrue( Hibernate.isInitialized( p.getEmployee().getEmployments() ) ); assertEquals( p.getEmployee().getEmployments().size(), 1 ); p2 = (Person) s.createQuery("from Person where name='Emmanuel'").uniqueResult(); assertNull( p2.getEmployee() ); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); p = (Person) s.get(Person.class, "Gavin"); //assertFalse( Hibernate.isPropertyInitialized(p, "employee") ); assertSame( p.getEmployee().getPerson(), p ); assertTrue( Hibernate.isInitialized( p.getEmployee().getEmployments() ) ); assertEquals( p.getEmployee().getEmployments().size(), 1 ); p2 = (Person) s.get(Person.class, "Emmanuel"); assertNull( p2.getEmployee() ); s.delete(p2); s.delete(old); s.delete(p); 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/extralazy/ExtraLazyTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/lazyonetoone/LazyOneToOneTest.java
Method name: void testRemoveClear() Method name: void testLazy()
Number of AST nodes: 37 Number of AST nodes: 35
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		User gavin = new User("gavin", "secret");
3
		Person p = new Person("Gavin"
4
		User turin = new User("turin", "tiger");
5
		Group g = new Group("developers");
6
		g.getUsers().put("gavin", gavin);
7
		g.getUsers().put("turin", turin);
8
		s.persist(g);
9
		gavin.getSession().put( "foo", new SessionAttribute("foo", "foo bar baz") );
10
		gavin.getSession().put( "bar", new SessionAttribute("bar", "foo bar baz 2") 
4
);
5
		Person p2 = new Person("Emmanuel");
6
		Employee e = new Employee(p);
7
		new Employment(e, "JBoss");
8
		Employment old = new Employment(e, "IFA");
9
		old.setEndDate( new Date() );
10
		s.persist(p);
11
);
11
		s.persist(p2);
12
		t.commit();
12
		t.commit();
13
		s.close();
13
		s.close();
14
		
14
		s = openSession();
15
		s = openSession();
15
		t = s.beginTransaction();
16
		t = s.beginTransaction();
16
		g = (Group) s.get(Group.class, "developers");
17
		p = (
17
		gavin = (User) g.getUsers().get("gavin");
18
Person) s.createQuery("from Person where name='Gavin'")
18
		turin = (User) g.getUsers().get("turin");
19
.uniqueResult();
19
		assertFalse( Hibernate.isInitialized( g.getUsers() ) );
20
		//assertFalse( Hibernate.isPropertyInitialized(
20
		g.getUsers().clear();
21
		gavin.getSession().remove("foo"
21
p, "employee") );
22
);
22
		assertSame( p.getEmployee().getPerson(), p );
23
		assertTrue( Hibernate.isInitialized( g.getUsers() ) );
23
		assertTrue( Hibernate.isInitialized( 
24
		assertTrue( Hibernate.isInitialized( gavin.getSession() 
24
p.getEmployee().getEmployments() ) );
25
		assertEquals( p.getEmployee().getEmployments().size(), 1 );
26
		p2 = (Person) s.createQuery("from Person where name='Emmanuel'").uniqueResult();
25
) );
27
		assertNull( p2.getEmployee() );
26
		t.commit();
28
		t.commit();
27
		s.close();
29
		s.close();
28
		s = openSession();
30
		s = openSession();
29
		t = s.beginTransaction();
31
		t = s.beginTransaction();
30
		g = (Group) s.get(Group.class, "developers"
32
		p = (Person) s.get(Person.class, "Gavin");
31
);
33
		//assertFalse( Hibernate.isPropertyInitialized(p, "employee") );
32
		assertTrue( g.getUsers().isEmpty() );
34
		assertSame( p.getEmployee().getPerson(), p );
33
		assertFalse( Hibernate.isInitialized( g.getUsers() ) );
35
		assertTrue( Hibernate.isInitialized( 
34
		gavin = (User) s.get(User.class, "gavin");
35
		assertFalse( gavin.getSession().containsKey("foo") );
36
		assertFalse( Hibernate.isInitialized( gavin.getSession() 
36
p.getEmployee().getEmployments() ) );
37
		assertEquals( p.getEmployee().getEmployments().size(), 1 );
38
		p2 = (Person) s.get(Person.class, "Emmanuel");
37
) );
39
		assertNull( p2.getEmployee() );
38
		s.delete(gavin);
40
		s.delete(p2);
39
		s.delete(turin);
41
		s.delete(old);
40
		s.delete(g);
42
		s.delete(p);
41
		t.commit();
43
		t.commit();
42
		s.close();
44
		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 comparisons677
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements21
    Number of unmapped statements in the first code fragment16
    Number of unmapped statements in the second code fragment14
    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
    Person p = new Person("Gavin");
    3
    User gavin = new User("gavin", "secret");
                                                                                      
                                                                            
    4
    Person p2 = new Person("Emmanuel");
    4
    User turin = new User("turin", "tiger");
                                                                                    
                                                                
    5
    Employee e = new Employee(p);
    5
    Group g = new Group("developers");
                                                                          
                                                              
    6
    new Employment(e, "JBoss");
    6
    g.getUsers().put("gavin", gavin);
                                                                          
                                                                                        
    7
    Employment old = new Employment(e, "IFA");
    7
    g.getUsers().put("turin", turin);
                                                                          
                                                                
    8
    old.setEndDate(new Date());
                                    
    9
    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
    9
    s.persist(p);
    8
    s.persist(g);
    8
    s.persist(g);
    10
    s.persist(p2);
    Differences
    Expression1Expression2Difference
    gp2VARIABLE_NAME_MISMATCH
    org.hibernate.test.extralazy.Grouporg.hibernate.test.lazyonetoone.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.extralazy.Group of variable g does not match with type org.hibernate.test.lazyonetoone.Person of variable p2
    • Make classes org.hibernate.test.extralazy.Group and org.hibernate.test.lazyonetoone.Person extend a common superclass
    10
    s.persist(p2);
    9
    gavin.getSession().put("foo", new SessionAttribute("foo", "foo bar baz"));
                                                                                                                                                          
    10
    gavin.getSession().put("bar", new SessionAttribute("bar", "foo bar baz 2"));
                                                                                                                                                                
    11
    t.commit();
    11
    t.commit();
    12
    s.close();
    12
    s.close();
    13
    s = openSession();
    13
    s = openSession();
    14
    t = s.beginTransaction();
    14
    t = s.beginTransaction();
                                                                                                                                                              
    15
    p = (Person)s.createQuery("from Person where name='Gavin'").uniqueResult();
    Preondition Violations
    Unmatched statement p=(Person)s.createQuery("from Person where name='Gavin'").uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15
    p = (Person)s.createQuery("from Person where name='Gavin'").uniqueResult();
    15
    g = (Group)s.get(Group.class, "developers");
    15
    g = (Group)s.get(Group.class, "developers");
    Preondition Violations
    Unmatched statement g=(Group)s.get(Group.class,"developers"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                              
    16
    gavin = (User)g.getUsers().get("gavin");
                                                                                        
    17
    turin = (User)g.getUsers().get("turin");
                                                                                        
    18
    assertFalse(Hibernate.isInitialized(g.getUsers()));
    18
    assertFalse(Hibernate.isInitialized(g.getUsers()));
    16
    assertSame(p.getEmployee().getPerson(), p);
    Differences
    Expression1Expression2Difference
    assertFalseassertSameMETHOD_INVOCATION_NAME_MISMATCH
    assertFalse(Hibernate.isInitialized(g.getUsers()))assertSame(p.getEmployee().getPerson(),p)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    16
    assertSame(p.getEmployee().getPerson(), p);
    19
    g.getUsers().clear();
    19
    g.getUsers().clear();
    17
    assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments()));
    Differences
    Expression1Expression2Difference
    clearassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    g.getUsers().clear()assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments()))ARGUMENT_NUMBER_MISMATCH
    g.getUsers()MISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression g.getUsers().clear() is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments())) is a void method call, and thus it cannot be parameterized
    Expression g.getUsers().clear() is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments())) is a void method call, and thus it cannot be parameterized
    17
    assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments()));
                                                                                                                                                                      
    19
    p2 = (Person)s.createQuery("from Person where name='Emmanuel'").uniqueResult();
    Preondition Violations
    Unmatched statement p2=(Person)s.createQuery("from Person where name='Emmanuel'").uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19
    p2 = (Person)s.createQuery("from Person where name='Emmanuel'").uniqueResult();
                                                                      
    20
    assertNull(p2.getEmployee());
    20
    gavin.getSession().remove("foo");
                                                                              
    21
    assertTrue(Hibernate.isInitialized(g.getUsers()));
    21
    assertTrue(Hibernate.isInitialized(g.getUsers()));
    18
    assertEquals(p.getEmployee().getEmployments().size(), 1);
    Differences
    Expression1Expression2Difference
    assertTrueassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertTrue(Hibernate.isInitialized(g.getUsers()))assertEquals(p.getEmployee().getEmployments().size(),1)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    18
    assertEquals(p.getEmployee().getEmployments().size(), 1);
    22
    assertTrue(Hibernate.isInitialized(gavin.getSession()));
                                                                                                                            
    23
    t.commit();
    21
    t.commit();
    24
    s.close();
    22
    s.close();
    25
    s = openSession();
    23
    s = openSession();
    26
    t = s.beginTransaction();
    24
    t = s.beginTransaction();
                                                                                        
    25
    p = (Person)s.get(Person.class, "Gavin");
    Preondition Violations
    Unmatched statement p=(Person)s.get(Person.class,"Gavin"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    25
    p = (Person)s.get(Person.class, "Gavin");
                                                                                                                                                        
    27
    assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments()));
    27
    g = (Group)s.get(Group.class, "developers");
    27
    g = (Group)s.get(Group.class, "developers");
    Preondition Violations
    Unmatched statement g=(Group)s.get(Group.class,"developers"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                              
    28
    assertTrue(g.getUsers().isEmpty());
    28
    assertTrue(g.getUsers().isEmpty());
    28
    assertEquals(p.getEmployee().getEmployments().size(), 1);
    Differences
    Expression1Expression2Difference
    assertTrueassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertTrue(g.getUsers().isEmpty())assertEquals(p.getEmployee().getEmployments().size(),1)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue(g.getUsers().isEmpty()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    Expression assertTrue(g.getUsers().isEmpty()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    28
    assertEquals(p.getEmployee().getEmployments().size(), 1);
    29
    assertFalse(Hibernate.isInitialized(g.getUsers()));
    29
    assertFalse(Hibernate.isInitialized(g.getUsers()));
    26
    assertSame(p.getEmployee().getPerson(), p);
    Differences
    Expression1Expression2Difference
    assertFalseassertSameMETHOD_INVOCATION_NAME_MISMATCH
    assertFalse(Hibernate.isInitialized(g.getUsers()))assertSame(p.getEmployee().getPerson(),p)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    26
    assertSame(p.getEmployee().getPerson(), p);
                                                                                                
    29
    p2 = (Person)s.get(Person.class, "Emmanuel");
    Preondition Violations
    Unmatched statement p2=(Person)s.get(Person.class,"Emmanuel"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    29
    p2 = (Person)s.get(Person.class, "Emmanuel");
                                                                      
    30
    assertNull(p2.getEmployee());
    30
    gavin = (User)s.get(User.class, "gavin");
    30
    gavin = (User)s.get(User.class, "gavin");
    Preondition Violations
    Unmatched statement gavin=(User)s.get(User.class,"gavin"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                        
    31
    assertFalse(gavin.getSession().containsKey("foo"));
                                                                                                                  
    32
    assertFalse(Hibernate.isInitialized(gavin.getSession()));
                                                                                                                              
    33
    s.delete(gavin);
    33
    s.delete(gavin);
    33
    s.delete(p);
    Differences
    Expression1Expression2Difference
    gavinpVARIABLE_NAME_MISMATCH
    org.hibernate.test.extralazy.Userorg.hibernate.test.lazyonetoone.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.extralazy.User of variable gavin does not match with type org.hibernate.test.lazyonetoone.Person of variable p
    • Make classes org.hibernate.test.extralazy.User and org.hibernate.test.lazyonetoone.Person extend a common superclass
    33
    s.delete(p);
    34
    s.delete(turin);
    34
    s.delete(turin);
    32
    s.delete(old);
    Differences
    Expression1Expression2Difference
    turinoldVARIABLE_NAME_MISMATCH
    org.hibernate.test.extralazy.Userorg.hibernate.test.lazyonetoone.EmploymentVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.extralazy.User of variable turin does not match with type org.hibernate.test.lazyonetoone.Employment of variable old
    • Make classes org.hibernate.test.extralazy.User and org.hibernate.test.lazyonetoone.Employment extend a common superclass
    32
    s.delete(old);
    35
    s.delete(g);
    35
    s.delete(g);
    31
    s.delete(p2);
    Differences
    Expression1Expression2Difference
    gp2VARIABLE_NAME_MISMATCH
    org.hibernate.test.extralazy.Grouporg.hibernate.test.lazyonetoone.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.extralazy.Group of variable g does not match with type org.hibernate.test.lazyonetoone.Person of variable p2
    • Make classes org.hibernate.test.extralazy.Group and org.hibernate.test.lazyonetoone.Person extend a common superclass
    31
    s.delete(p2);
    36
    t.commit();
    34
    t.commit();
    37
    s.close();
    35
    s.close();
    Precondition Violations (32)
    Row Violation
    1Unmatched statement s.persist(p); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Type org.hibernate.test.extralazy.Group of variable g does not match with type org.hibernate.test.lazyonetoone.Person of variable p2
    3Unmatched statement p=(Person)s.createQuery("from Person where name='Gavin'").uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement g=(Group)s.get(Group.class,"developers"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    6Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    7Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    8Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    9Expression g.getUsers().clear() is a void method call, and thus it cannot be parameterized
    10Expression assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments())) is a void method call, and thus it cannot be parameterized
    11Expression g.getUsers().clear() is a void method call, and thus it cannot be parameterized
    12Expression assertTrue(Hibernate.isInitialized(p.getEmployee().getEmployments())) is a void method call, and thus it cannot be parameterized
    13Unmatched statement p2=(Person)s.createQuery("from Person where name='Emmanuel'").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())) is a void method call, and thus it cannot be parameterized
    15Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    16Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    17Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    18Unmatched statement p=(Person)s.get(Person.class,"Gavin"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement g=(Group)s.get(Group.class,"developers"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Expression assertTrue(g.getUsers().isEmpty()) is a void method call, and thus it cannot be parameterized
    21Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    22Expression assertTrue(g.getUsers().isEmpty()) is a void method call, and thus it cannot be parameterized
    23Expression assertEquals(p.getEmployee().getEmployments().size(),1) is a void method call, and thus it cannot be parameterized
    24Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    25Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    26Expression assertFalse(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized
    27Expression assertSame(p.getEmployee().getPerson(),p) is a void method call, and thus it cannot be parameterized
    28Unmatched statement p2=(Person)s.get(Person.class,"Emmanuel"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    29Unmatched statement gavin=(User)s.get(User.class,"gavin"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    30Type org.hibernate.test.extralazy.User of variable gavin does not match with type org.hibernate.test.lazyonetoone.Person of variable p
    31Type org.hibernate.test.extralazy.User of variable turin does not match with type org.hibernate.test.lazyonetoone.Employment of variable old
    32Type org.hibernate.test.extralazy.Group of variable g does not match with type org.hibernate.test.lazyonetoone.Person of variable p2