Session s = openSession(); Transaction t = s.beginTransaction(); Employee mark = new Employee(); mark.setName("Mark"); mark.setTitle("internal sales"); mark.setSex('M'); mark.setAddress("buckhead"); mark.setZip("30305"); mark.setCountry("USA"); Customer joe = new Customer(); joe.setName("Joe"); joe.setAddress("San Francisco"); joe.setZip("XXXXX"); joe.setCountry("USA"); joe.setComments("Very demanding"); joe.setSex('M'); joe.setSalesperson(mark); Person yomomma = new Person(); yomomma.setName("mum"); yomomma.setSex('F'); s.save(yomomma); s.save(mark); s.save(joe); assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 ); assertEquals( s.createQuery("from Person").list().size(), 3 ); assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 ); assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 ); s.clear(); List customers = s.createQuery("from Customer c left join fetch c.salesperson").list(); for ( Iterator iter = customers.iterator(); iter.hasNext(); ) { Customer c = (Customer) iter.next(); assertTrue( Hibernate.isInitialized( c.getSalesperson() ) ); assertEquals( c.getSalesperson().getName(), "Mark" ); } assertEquals( customers.size(), 1 ); s.clear(); customers = s.createQuery("from Customer").list(); for ( Iterator iter = customers.iterator(); iter.hasNext(); ) { Customer c = (Customer) iter.next(); assertFalse( Hibernate.isInitialized( c.getSalesperson() ) ); assertEquals( c.getSalesperson().getName(), "Mark" ); } assertEquals( customers.size(), 1 ); s.clear(); mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) ); joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) ); mark.setZip("30306"); assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 ); if ( supportsRowValueConstructorSyntaxInInList() ) { s.createCriteria(Person.class).add( Restrictions.in("address", new Address[] { mark.getAddress(), joe.getAddress() } ) ).list(); } s.delete(mark); s.delete(joe); s.delete(yomomma); assertTrue( s.createQuery("from Person").list().isEmpty() ); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Employee mark = new Employee(); mark.setName("Mark"); mark.setTitle("internal sales"); mark.setSex('M'); mark.setAddress("buckhead"); mark.setZip("30305"); mark.setCountry("USA"); Customer joe = new Customer(); joe.setName("Joe"); joe.setAddress("San Francisco"); joe.setZip("XXXXX"); joe.setCountry("USA"); joe.setComments("Very demanding"); joe.setSex('M'); joe.setSalesperson(mark); Person yomomma = new Person(); yomomma.setName("mum"); yomomma.setSex('F'); s.save(yomomma); s.save(mark); s.save(joe); assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 ); assertEquals( s.createQuery("from Person").list().size(), 3 ); assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 ); assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 ); s.clear(); List customers = s.createQuery("from Customer c left join fetch c.salesperson").list(); for ( Iterator iter = customers.iterator(); iter.hasNext(); ) { Customer c = (Customer) iter.next(); assertTrue( Hibernate.isInitialized( c.getSalesperson() ) ); assertEquals( c.getSalesperson().getName(), "Mark" ); } assertEquals( customers.size(), 1 ); s.clear(); customers = s.createQuery("from Customer").list(); for ( Iterator iter = customers.iterator(); iter.hasNext(); ) { Customer c = (Customer) iter.next(); assertFalse( Hibernate.isInitialized( c.getSalesperson() ) ); assertEquals( c.getSalesperson().getName(), "Mark" ); } assertEquals( customers.size(), 1 ); s.clear(); mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) ); joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) ); mark.setZip("30306"); assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 ); if ( supportsRowValueConstructorSyntaxInInList() ) { s.createCriteria(Person.class).add( Restrictions.in("address", new Address[] { mark.getAddress(), joe.getAddress() } ) ).list(); } s.delete(mark); s.delete(joe); s.delete(yomomma); assertTrue( s.createQuery("from Person").list().isEmpty() ); 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/unionsubclass2/UnionSubclassTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/joinedsubclass/JoinedSubclassTest.java
Method name: void testUnionSubclass() Method name: void testJoinedSubclass()
Number of AST nodes: 54 Number of AST nodes: 54
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		
4
		Employee mark = new Employee();
3
		Employee mark = new Employee();
5
		mark.setName("Mark");
4
		mark.setName("Mark");
6
		mark.setTitle("internal sales");
5
		mark.setTitle("internal sales");
7
		mark.setSex('M');
6
		mark.setSex('M');
8
		mark.setAddress("buckhead");
7
		mark.setAddress("buckhead");
9
		mark.setZip("30305");
8
		mark.setZip("30305");
10
		mark.setCountry("USA");
9
		mark.setCountry("USA");
11
		
12
		Customer joe = new Customer();
10
		Customer joe = new Customer();
13
		joe.setName("Joe");
11
		joe.setName("Joe");
14
		joe.setAddress("San Francisco");
12
		joe.setAddress("San Francisco");
15
		joe.setZip("XXXXX");
13
		joe.setZip("XXXXX");
16
		joe.setCountry("USA");
14
		joe.setCountry("USA");
17
		joe.setComments("Very demanding");
15
		joe.setComments("Very demanding");
18
		joe.setSex('M');
16
		joe.setSex('M');
19
		joe.setSalesperson(mark);
17
		joe.setSalesperson(mark);
20
		
21
		Person yomomma = new Person();
18
		Person yomomma = new Person();
22
		yomomma.setName("mum");
19
		yomomma.setName("mum");
23
		yomomma.setSex('F');
20
		yomomma.setSex('F');
24
		
25
		s.save(yomomma);
21
		s.save(yomomma);
26
		s.save(mark);
22
		s.save(mark);
27
		s.save(joe);
23
		s.save(joe);
28
		
29
		assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );
24
		assertEquals( s.createQuery("from java.io.Serializable").list().size(), 0 );
30
		
31
		assertEquals( s.createQuery("from Person").list().size(), 3 );
25
		assertEquals( s.createQuery("from Person").list().size(), 3 );
32
		assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );
26
		assertEquals( s.createQuery("from Person p where p.class = Customer").list().size(), 1 );
33
		assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
27
		assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
34
		s.clear();
28
		s.clear();
35
		List customers = s.createQuery("from Customer c left join fetch c.salesperson").list();
29
		List customers = s.createQuery("from Customer c left join fetch c.salesperson").list();
36
		for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
30
		for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
37
			Customer c = (Customer) iter.next();
31
			Customer c = (Customer) iter.next();
38
			assertTrue( Hibernate.isInitialized( c.getSalesperson() ) );
32
			assertTrue( Hibernate.isInitialized( c.getSalesperson() ) );
39
			assertEquals( c.getSalesperson().getName(), "Mark" );
33
			assertEquals( c.getSalesperson().getName(), "Mark" );
40
		}
34
		}
41
		assertEquals( customers.size(), 1 );
35
		assertEquals( customers.size(), 1 );
42
		s.clear();
36
		s.clear();
43
		
44
		customers = s.createQuery("from Customer").list();
37
		customers = s.createQuery("from Customer").list();
45
		for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
38
		for ( Iterator iter = customers.iterator(); iter.hasNext(); ) {
46
			Customer c = (Customer) iter.next();
39
			Customer c = (Customer) iter.next();
47
			assertFalse( Hibernate.isInitialized( c.getSalesperson() ) );
40
			assertFalse( Hibernate.isInitialized( c.getSalesperson() ) );
48
			assertEquals( c.getSalesperson().getName(), "Mark" );
41
			assertEquals( c.getSalesperson().getName(), "Mark" );
49
		}
42
		}
50
		assertEquals( customers.size(), 1 );
43
		assertEquals( customers.size(), 1 );
51
		s.clear();
44
		s.clear();
52
		
53
		mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );
45
		mark = (Employee) s.get( Employee.class, new Long( mark.getId() ) );
54
		joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );
46
		joe = (Customer) s.get( Customer.class, new Long( joe.getId() ) );
55
		
56
 		mark.setZip("30306");
47
 		mark.setZip("30306");
57
		assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );
48
		assertEquals( s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1 );
58
		if ( supportsRowValueConstructorSyntaxInInList() ) {
49
		if ( supportsRowValueConstructorSyntaxInInList() ) {
59
			s.createCriteria(Person.class).add( 
50
			s.createCriteria(Person.class).add(
60
					Restrictions.in("address", new Address[] { mark.getAddress(), joe.getAddress() } ) 
51
					Restrictions.in("address", new Address[] { mark.getAddress(), joe.getAddress() } )
61
			).list();
52
			).list();
62
		}
53
		}
63
		
64
		s.delete(mark);
54
		s.delete(mark);
65
		s.delete(joe);
55
		s.delete(joe);
66
		s.delete(yomomma);
56
		s.delete(yomomma);
67
		assertTrue( s.createQuery("from Person").list().isEmpty() );
57
		assertTrue( s.createQuery("from Person").list().isEmpty() );
68
		t.commit();
58
		t.commit();
69
		s.close();
59
		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.9
Clones locationClones are in different classes having the same super class
Number of node comparisons834
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements54
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)97.1
    Clone typeType 2
    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
    Employee mark = new Employee();
    3
    Employee mark = new Employee();
    4
    mark.setName("Mark");
    4
    mark.setName("Mark");
    5
    mark.setTitle("internal sales");
    5
    mark.setTitle("internal sales");
    6
    mark.setSex('M');
    6
    mark.setSex('M');
    7
    mark.setAddress("buckhead");
    7
    mark.setAddress("buckhead");
    12
    joe.setAddress("San Francisco");
    Differences
    Expression1Expression2Difference
    "buckhead""San Francisco"LITERAL_VALUE_MISMATCH
    markjoeVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Employeeorg.hibernate.test.joinedsubclass.CustomerSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12
    joe.setAddress("San Francisco");
    8
    mark.setZip("30305");
    8
    mark.setZip("30305");
    9
    mark.setCountry("USA");
    9
    mark.setCountry("USA");
    10
    Customer joe = new Customer();
    10
    Customer joe = new Customer();
    11
    joe.setName("Joe");
    11
    joe.setName("Joe");
    12
    joe.setAddress("San Francisco");
    12
    joe.setAddress("San Francisco");
    7
    mark.setAddress("buckhead");
    Differences
    Expression1Expression2Difference
    "San Francisco""buckhead"LITERAL_VALUE_MISMATCH
    joemarkVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Customerorg.hibernate.test.joinedsubclass.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7
    mark.setAddress("buckhead");
    13
    joe.setZip("XXXXX");
    13
    joe.setZip("XXXXX");
    14
    joe.setCountry("USA");
    14
    joe.setCountry("USA");
    15
    joe.setComments("Very demanding");
    15
    joe.setComments("Very demanding");
    16
    joe.setSex('M');
    16
    joe.setSex('M');
    17
    joe.setSalesperson(mark);
    17
    joe.setSalesperson(mark);
    18
    Person yomomma = new Person();
    18
    Person yomomma = new Person();
    19
    yomomma.setName("mum");
    19
    yomomma.setName("mum");
    20
    yomomma.setSex('F');
    20
    yomomma.setSex('F');
    21
    s.save(yomomma);
    21
    s.save(yomomma);
    22
    s.save(mark);
    22
    s.save(mark);
    23
    s.save(joe);
    Differences
    Expression1Expression2Difference
    markjoeVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Employeeorg.hibernate.test.joinedsubclass.CustomerSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23
    s.save(joe);
    23
    s.save(joe);
    23
    s.save(joe);
    22
    s.save(mark);
    Differences
    Expression1Expression2Difference
    joemarkVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Customerorg.hibernate.test.joinedsubclass.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22
    s.save(mark);
    24
    assertEquals(s.createQuery("from java.io.Serializable").list().size(), 0);
    24
    assertEquals(s.createQuery("from java.io.Serializable").list().size(), 0);
    25
    assertEquals(s.createQuery("from Person").list().size(), 3);
    25
    assertEquals(s.createQuery("from Person").list().size(), 3);
    26
    assertEquals(s.createQuery("from Person p where p.class = Customer").list().size(), 1);
    26
    assertEquals(s.createQuery("from Person p where p.class = Customer").list().size(), 1);
    27
    assertEquals(s.createQuery("from Person p where p.class = Person").list().size(), 1);
    27
    assertEquals(s.createQuery("from Person p where p.class = Person").list().size(), 1);
    28
    s.clear();
    28
    s.clear();
    29
    List customers = s.createQuery("from Customer c left join fetch c.salesperson").list();
    29
    List customers = s.createQuery("from Customer c left join fetch c.salesperson").list();
    30
    for (Iterator iter = customers.iterator(); iter.hasNext(); )
    30
    for (Iterator iter = customers.iterator(); iter.hasNext(); )
    31
    Customer c = (Customer)iter.next();
    31
    Customer c = (Customer)iter.next();
    32
    assertTrue(Hibernate.isInitialized(c.getSalesperson()));
    32
    assertTrue(Hibernate.isInitialized(c.getSalesperson()));
    33
    assertEquals(c.getSalesperson().getName(), "Mark");
    33
    assertEquals(c.getSalesperson().getName(), "Mark");
    34
    assertEquals(customers.size(), 1);
    34
    assertEquals(customers.size(), 1);
    35
    s.clear();
    35
    s.clear();
    36
    customers = s.createQuery("from Customer").list();
    36
    customers = s.createQuery("from Customer").list();
    37
    for (Iterator iter = customers.iterator(); iter.hasNext(); )
    37
    for (Iterator iter = customers.iterator(); iter.hasNext(); )
    38
    Customer c = (Customer)iter.next();
    38
    Customer c = (Customer)iter.next();
    39
    assertFalse(Hibernate.isInitialized(c.getSalesperson()));
    39
    assertFalse(Hibernate.isInitialized(c.getSalesperson()));
    40
    assertEquals(c.getSalesperson().getName(), "Mark");
    40
    assertEquals(c.getSalesperson().getName(), "Mark");
    41
    assertEquals(customers.size(), 1);
    41
    assertEquals(customers.size(), 1);
    42
    s.clear();
    42
    s.clear();
    43
    mark = (Employee)s.get(Employee.class, new Long(mark.getId()));
    43
    mark = (Employee)s.get(Employee.class, new Long(mark.getId()));
    44
    joe = (Customer)s.get(Customer.class, new Long(joe.getId()));
    Differences
    Expression1Expression2Difference
    markjoeVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Employeeorg.hibernate.test.joinedsubclass.CustomerSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.unionsubclass2.Employeeorg.hibernate.test.joinedsubclass.CustomerSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Employee)s.get(Employee.class,new Long(mark.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Customer)s.get(Customer.class,new Long(joe.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    44
    joe = (Customer)s.get(Customer.class, new Long(joe.getId()));
    44
    joe = (Customer)s.get(Customer.class, new Long(joe.getId()));
    44
    joe = (Customer)s.get(Customer.class, new Long(joe.getId()));
    43
    mark = (Employee)s.get(Employee.class, new Long(mark.getId()));
    Differences
    Expression1Expression2Difference
    joemarkVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Customerorg.hibernate.test.joinedsubclass.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.unionsubclass2.Customerorg.hibernate.test.joinedsubclass.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Customer)s.get(Customer.class,new Long(joe.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Employee)s.get(Employee.class,new Long(mark.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    43
    mark = (Employee)s.get(Employee.class, new Long(mark.getId()));
    45
    mark.setZip("30306");
    45
    mark.setZip("30306");
    46
    assertEquals(s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1);
    46
    assertEquals(s.createQuery("from Person p where p.address.zip = '30306'").list().size(), 1);
    47
    if (supportsRowValueConstructorSyntaxInInList())
    47
    if (supportsRowValueConstructorSyntaxInInList())
    48
    s.createCriteria(Person.class).add(Restrictions.in("address", new Address[] {mark.getAddress(), joe.getAddress()})).list();
    48
    s.createCriteria(Person.class).add(Restrictions.in("address", new Address[] {mark.getAddress(), joe.getAddress()})).list();
    49
    s.delete(mark);
    49
    s.delete(mark);
    50
    s.delete(joe);
    Differences
    Expression1Expression2Difference
    markjoeVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Employeeorg.hibernate.test.joinedsubclass.CustomerSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    50
    s.delete(joe);
    50
    s.delete(joe);
    50
    s.delete(joe);
    49
    s.delete(mark);
    Differences
    Expression1Expression2Difference
    joemarkVARIABLE_NAME_MISMATCH
    org.hibernate.test.unionsubclass2.Customerorg.hibernate.test.joinedsubclass.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    49
    s.delete(mark);
    51
    s.delete(yomomma);
    51
    s.delete(yomomma);
    52
    assertTrue(s.createQuery("from Person").list().isEmpty());
    52
    assertTrue(s.createQuery("from Person").list().isEmpty());
    53
    t.commit();
    53
    t.commit();
    54
    s.close();
    54
    s.close();
    Precondition Violations (20)
    Row Violation
    1Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression (Employee)s.get(Employee.class,new Long(mark.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression (Customer)s.get(Customer.class,new Long(joe.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression (Customer)s.get(Customer.class,new Long(joe.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Expression (Employee)s.get(Employee.class,new Long(mark.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19Expression joe cannot be parameterized, because it has dependencies to/from statements that will be extracted
    20Expression mark cannot be parameterized, because it has dependencies to/from statements that will be extracted