Session s = openSession(); Transaction t = s.beginTransaction(); Person p = new Person(); p.setName("Emmanuel"); p.setSex('M'); s.persist(p); Employee q = new Employee(); q.setName("Steve"); q.setSex('M'); q.setTitle("Mr"); q.setSalary( new BigDecimal(1000) ); s.persist(q); List result = s.createQuery("from Person where salary > 100").list(); assertEquals( result.size(), 1 ); assertSame( result.get(0), q ); result = s.createQuery("from Person where salary > 100 or name like 'E%'").list(); assertEquals( result.size(), 2 ); result = s.createCriteria(Person.class) .add( Property.forName("salary").gt( new BigDecimal(100) ) ) .list(); assertEquals( result.size(), 1 ); assertSame( result.get(0), q ); //TODO: make this work: /*result = s.createQuery("select salary from Person where salary > 100").list(); assertEquals( result.size(), 1 ); assertEquals( result.get(0), new BigDecimal(1000) );*/ s.delete(p); s.delete(q); t.commit(); s.close();
Session s = openSession(); Transaction t = s.beginTransaction(); Person p = new Person(); p.setName("Emmanuel"); p.setSex('M'); s.persist(p); Employee q = new Employee(); q.setName("Steve"); q.setSex('M'); q.setTitle("Mr"); q.setSalary( new BigDecimal(1000) ); s.persist(q); List result = s.createQuery("from Person where salary > 100").list(); assertEquals( result.size(), 1 ); assertSame( result.get(0), q ); result = s.createQuery("from Person where salary > 100 or name like 'E%'").list(); assertEquals( result.size(), 2 ); result = s.createCriteria(Person.class) .add( Property.forName("salary").gt( new BigDecimal(100) ) ) .list(); assertEquals( result.size(), 1 ); assertSame( result.get(0), q ); //TODO: make this work: /*result = s.createQuery("select salary from Person where salary > 100").list(); assertEquals( result.size(), 1 ); assertEquals( result.get(0), new BigDecimal(1000) );*/ s.delete(p); s.delete(q); 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/joinedsubclass/JoinedSubclassTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/discriminator/DiscriminatorTest.java
Method name: void testQuerySubclassAttribute() Method name: void testQuerySubclassAttribute()
Number of AST nodes: 24 Number of AST nodes: 24
1
Session s = openSession();
1
Session s = openSession();
2
		Transaction t = s.beginTransaction();
2
		Transaction t = s.beginTransaction();
3
		Person p = new Person();
3
		Person p = new Person();
4
		p.setName("Emmanuel");
4
		p.setName("Emmanuel");
5
		p.setSex('M');
5
		p.setSex('M');
6
		s.persist(p);
6
		s.persist(p);
7
		Employee q = new Employee();
7
		Employee q = new Employee();
8
		q.setName("Steve");
8
		q.setName("Steve");
9
		q.setSex('M');
9
		q.setSex('M');
10
		q.setTitle("Mr");
10
		q.setTitle("Mr");
11
		q.setSalary( new BigDecimal(1000) );
11
		q.setSalary( new BigDecimal(1000) );
12
		s.persist(q);
12
		s.persist(q);
13
		List result = s.createQuery("from Person where salary > 100").list();
13
		List result = s.createQuery("from Person where salary > 100").list();
14
		assertEquals( result.size(), 1 );
14
		assertEquals( result.size(), 1 );
15
		assertSame( result.get(0), q );
15
		assertSame( result.get(0), q );
16
		result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
16
		result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
17
		assertEquals( result.size(), 2 );
17
		assertEquals( result.size(), 2 );
18
		result = s.createCriteria(Person.class)
18
		result = s.createCriteria(Person.class)
19
			.add( Property.forName("salary").gt( new BigDecimal(100) ) )
19
			.add( Property.forName("salary").gt( new BigDecimal(100) ) )
20
			.list();
20
			.list();
21
		assertEquals( result.size(), 1 );
21
		assertEquals( result.size(), 1 );
22
		assertSame( result.get(0), q );
22
		assertSame( result.get(0), q );
23
		//TODO: make this work:
23
		//TODO: make this work:
24
		/*result = s.createQuery("select salary from Person where salary > 100").list();
24
		/*result = s.createQuery("select salary from Person where salary > 100").list();
25
		assertEquals( result.size(), 1 );
25
		assertEquals( result.size(), 1 );
26
		assertEquals( result.get(0), new BigDecimal(1000) );*/
26
		assertEquals( result.get(0), new BigDecimal(1000) );*/
27
		s.delete(p);
27
		s.delete(p);
28
		s.delete(q);
28
		s.delete(q);
29
		t.commit();
29
		t.commit();
30
		s.close();
30
		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 comparisons197
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements23
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    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
    Person p = new Person();
    3
    Person p = new Person();
                                                      
    4
    p.setName("Emmanuel");
    4
    p.setName("Emmanuel");
    4
    p.setName("Emmanuel");
    Differences
    Expression1Expression2Difference
    org.hibernate.test.joinedsubclass.Personorg.hibernate.test.discriminator.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    • Make classes org.hibernate.test.joinedsubclass.Person and org.hibernate.test.discriminator.Person extend a common superclass
    4
    p.setName("Emmanuel");
    5
    p.setSex('M');
    5
    p.setSex('M');
    5
    p.setSex('M');
    Differences
    Expression1Expression2Difference
    org.hibernate.test.joinedsubclass.Personorg.hibernate.test.discriminator.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    • Make classes org.hibernate.test.joinedsubclass.Person and org.hibernate.test.discriminator.Person extend a common superclass
    5
    p.setSex('M');
    6
    s.persist(p);
    6
    s.persist(p);
    6
    s.persist(p);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.joinedsubclass.Personorg.hibernate.test.discriminator.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    • Make classes org.hibernate.test.joinedsubclass.Person and org.hibernate.test.discriminator.Person extend a common superclass
    6
    s.persist(p);
    7
    Employee q = new Employee();
    7
    Employee q = new Employee();
    8
    q.setName("Steve");
    8
    q.setName("Steve");
    9
    q.setSex('M');
    9
    q.setSex('M');
    10
    q.setTitle("Mr");
    10
    q.setTitle("Mr");
    11
    q.setSalary(new BigDecimal(1000));
    11
    q.setSalary(new BigDecimal(1000));
    12
    s.persist(q);
    12
    s.persist(q);
    13
    List result = s.createQuery("from Person where salary > 100").list();
    13
    List result = s.createQuery("from Person where salary > 100").list();
    14
    assertEquals(result.size(), 1);
    14
    assertEquals(result.size(), 1);
    15
    assertSame(result.get(0), q);
    15
    assertSame(result.get(0), q);
    16
    result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
    16
    result = s.createQuery("from Person where salary > 100 or name like 'E%'").list();
    17
    assertEquals(result.size(), 2);
    17
    assertEquals(result.size(), 2);
    18
    result = s.createCriteria(Person.class).add(Property.forName("salary").gt(new BigDecimal(100))).list();
    18
    result = s.createCriteria(Person.class).add(Property.forName("salary").gt(new BigDecimal(100))).list();
    19
    assertEquals(result.size(), 1);
    19
    assertEquals(result.size(), 1);
    20
    assertSame(result.get(0), q);
    20
    assertSame(result.get(0), q);
    21
    s.delete(p);
    21
    s.delete(p);
    21
    s.delete(p);
    Differences
    Expression1Expression2Difference
    org.hibernate.test.joinedsubclass.Personorg.hibernate.test.discriminator.PersonVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    • Make classes org.hibernate.test.joinedsubclass.Person and org.hibernate.test.discriminator.Person extend a common superclass
    21
    s.delete(p);
    22
    s.delete(q);
    22
    s.delete(q);
    23
    t.commit();
    23
    t.commit();
    24
    s.close();
    24
    s.close();
    Precondition Violations (4)
    Row Violation
    1Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    2Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    3Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p
    4Type org.hibernate.test.joinedsubclass.Person of variable p does not match with type org.hibernate.test.discriminator.Person of variable p