Session s = openSession(); s.beginTransaction(); Employee e = new Employee(); e.setName( "Steve" ); e.setSex( 'M' ); e.setTitle( "grand poobah" ); s.save( e ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); // load the superclass proxy. Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) ); assertTrue( pLoad instanceof HibernateProxy); Person pGet = ( Person ) s.get( Person.class, new Long( e.getId() )); Person pQuery = ( Person ) s.createQuery( "from Person where id = :id" ) .setLong( "id", e.getId() ) .uniqueResult(); Person pCriteria = ( Person ) s.createCriteria( Person.class ) .add( Restrictions.idEq( new Long( e.getId() ) ) ) .uniqueResult(); // assert that executing the queries polymorphically returns the same proxy assertSame( pLoad, pGet ); assertSame( pLoad, pQuery ); assertSame( pLoad, pCriteria ); // assert that the proxy is not an instance of Employee assertFalse( pLoad instanceof Employee ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.delete( e ); s.getTransaction().commit(); s.close();
Session s = openSession(); s.beginTransaction(); Employee e = new Employee(); e.setName( "Steve" ); e.setSex( 'M' ); e.setTitle( "grand poobah" ); s.save( e ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); // load the superclass proxy. Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) ); assertTrue( pLoad instanceof HibernateProxy); // evict the proxy s.evict( pLoad ); Employee pGet = ( Employee ) s.get( Person.class, new Long( e.getId() )); Employee pQuery = ( Employee ) s.createQuery( "from Person where id = :id" ) .setLong( "id", e.getId() ) .uniqueResult(); Employee pCriteria = ( Employee ) s.createCriteria( Person.class ) .add( Restrictions.idEq( new Long( e.getId() ) ) ) .uniqueResult(); // assert that executing the queries polymorphically returns the same Employee instance assertSame( pGet, pQuery ); assertSame( pGet, pCriteria ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); s.delete( e ); 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/discriminator/DiscriminatorTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/discriminator/DiscriminatorTest.java
Method name: void testLoadSuperclassProxyPolymorphicAccess() Method name: void testLoadSuperclassProxyEvictPolymorphicAccess()
Number of AST nodes: 27 Number of AST nodes: 26
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		s.beginTransaction();
3
		Employee e = new Employee();
3
		Employee e = new Employee();
4
		e.setName( "Steve" );
4
		e.setName( "Steve" );
5
		e.setSex( 'M' );
5
		e.setSex( 'M' );
6
		e.setTitle( "grand poobah" );
6
		e.setTitle( "grand poobah" );
7
		s.save( e );
7
		s.save( e );
8
		s.getTransaction().commit();
8
		s.getTransaction().commit();
9
		s.close();
9
		s.close();
10
		s = openSession();
10
		s = openSession();
11
		s.beginTransaction();
11
		s.beginTransaction();
12
		// load the superclass proxy.
12
		// load the superclass proxy.
13
		Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) );
13
		Person pLoad = ( Person ) s.load( Person.class, new Long( e.getId() ) );
14
		assertTrue( pLoad instanceof HibernateProxy);
14
		assertTrue( pLoad instanceof HibernateProxy);
15
		Person
15
		// evict the proxy
16
		s.evict( pLoad );
16
 pGet = ( Person ) s.get( Person.class, new Long( e.getId() ));
17
		Employee pGet = ( Employee ) s.get( Person.class, new Long( e.getId() ));
17
		Person pQuery = ( Person ) s.createQuery( "from Person where id = :id" )
18
		Employee pQuery = ( Employee ) s.createQuery( "from Person where id = :id" )
18
				.setLong( "id", e.getId() )
19
				.setLong( "id", e.getId() )
19
				.uniqueResult();
20
				.uniqueResult();
20
		Person pCriteria = ( Person ) s.createCriteria( Person.class )
21
		Employee pCriteria = ( Employee ) s.createCriteria( Person.class )
21
				.add( Restrictions.idEq( new Long( e.getId() ) ) )
22
				.add( Restrictions.idEq( new Long( e.getId() ) ) )
22
				.uniqueResult();
23
				.uniqueResult();
23
		// assert that executing the queries polymorphically returns the same proxy
24
		// assert that executing the queries polymorphically returns the same 
24
		assertSame( pLoad, pGet );
25
Employee instance
25
		assertSame( pLoad, pQuery );
26
		assertSame( pGet, pQuery );
26
		assertSame( pLoad, pCriteria );
27
		assertSame( pGet, pCriteria );
27
		// assert that the proxy is not an instance of Employee
28
		assertFalse( pLoad instanceof Employee );
29
		s.getTransaction().commit();
28
		s.getTransaction().commit();
30
		s.close();
29
		s.close();
31
		s = openSession();
30
		s = openSession();
32
		s.beginTransaction();
31
		s.beginTransaction();
33
		s.delete( e );
32
		s.delete( e );
34
		s.getTransaction().commit();
33
		s.getTransaction().commit();
35
		s.close();
34
		s.close();
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are declared in the same class
Number of node comparisons179
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements25
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment1
    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
    s.beginTransaction();
    2
    s.beginTransaction();
    3
    Employee e = new Employee();
    3
    Employee e = new Employee();
    4
    e.setName("Steve");
    4
    e.setName("Steve");
    5
    e.setSex('M');
    5
    e.setSex('M');
    6
    e.setTitle("grand poobah");
    6
    e.setTitle("grand poobah");
    7
    s.save(e);
    7
    s.save(e);
    8
    s.getTransaction().commit();
    8
    s.getTransaction().commit();
    9
    s.close();
    9
    s.close();
    10
    s = openSession();
    10
    s = openSession();
    11
    s.beginTransaction();
    11
    s.beginTransaction();
    12
    Person pLoad = (Person)s.load(Person.class, new Long(e.getId()));
    12
    Person pLoad = (Person)s.load(Person.class, new Long(e.getId()));
    13
    assertTrue(pLoad instanceof HibernateProxy);
    13
    assertTrue(pLoad instanceof HibernateProxy);
                                          
    14
    s.evict(pLoad);
    Preondition Violations
    Unmatched statement s.evict(pLoad); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    s.evict(pLoad);
    14
    Person pGet = (Person)s.get(Person.class, new Long(e.getId()));
    14
    Person pGet = (Person)s.get(Person.class, new Long(e.getId()));
    15
    Employee pGet = (Employee)s.get(Person.class, new Long(e.getId()));
    Differences
    Expression1Expression2Difference
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression (Person)s.get(Person.class,new Long(e.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Employee)s.get(Person.class,new Long(e.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15
    Employee pGet = (Employee)s.get(Person.class, new Long(e.getId()));
    15
    Person pQuery = (Person)s.createQuery("from Person where id = :id").setLong("id", e.getId()).uniqueResult();
    15
    Person pQuery = (Person)s.createQuery("from Person where id = :id").setLong("id", e.getId()).uniqueResult();
    16
    Employee pQuery = (Employee)s.createQuery("from Person where id = :id").setLong("id", e.getId()).uniqueResult();
    Differences
    Expression1Expression2Difference
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression (Person)s.createQuery("from Person where id = :id").setLong("id",e.getId()).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Employee)s.createQuery("from Person where id = :id").setLong("id",e.getId()).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16
    Employee pQuery = (Employee)s.createQuery("from Person where id = :id").setLong("id", e.getId()).uniqueResult();
    16
    Person pCriteria = (Person)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult();
    16
    Person pCriteria = (Person)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult();
    17
    Employee pCriteria = (Employee)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult();
    Differences
    Expression1Expression2Difference
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression (Person)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression (Employee)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17
    Employee pCriteria = (Employee)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult();
    17
    assertSame(pLoad, pGet);
    17
    assertSame(pLoad, pGet);
    19
    assertSame(pGet, pCriteria);
    Differences
    Expression1Expression2Difference
    pLoadpGetVARIABLE_NAME_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    pGetpCriteriaVARIABLE_NAME_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression pLoad cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression pCriteria cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19
    assertSame(pGet, pCriteria);
    18
    assertSame(pLoad, pQuery);
    18
    assertSame(pLoad, pQuery);
    18
    assertSame(pGet, pQuery);
    Differences
    Expression1Expression2Difference
    pLoadpGetVARIABLE_NAME_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    org.hibernate.test.discriminator.Personorg.hibernate.test.discriminator.EmployeeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression pLoad cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18
    assertSame(pGet, pQuery);
    19
    assertSame(pLoad, pCriteria);
    19
    assertSame(pLoad, pCriteria);
    Preondition Violations
    Unmatched statement assertSame(pLoad,pCriteria); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                    
    20
    assertFalse(pLoad instanceof Employee);
    20
    assertFalse(pLoad instanceof Employee);
    Preondition Violations
    Unmatched statement assertFalse(pLoad instanceof Employee); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                          
    21
    s.getTransaction().commit();
    20
    s.getTransaction().commit();
    22
    s.close();
    21
    s.close();
    23
    s = openSession();
    22
    s = openSession();
    24
    s.beginTransaction();
    23
    s.beginTransaction();
    25
    s.delete(e);
    24
    s.delete(e);
    26
    s.getTransaction().commit();
    25
    s.getTransaction().commit();
    27
    s.close();
    26
    s.close();
    Precondition Violations (15)
    Row Violation
    1Unmatched statement s.evict(pLoad); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression (Person)s.get(Person.class,new Long(e.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression (Employee)s.get(Person.class,new Long(e.getId())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression (Person)s.createQuery("from Person where id = :id").setLong("id",e.getId()).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression (Employee)s.createQuery("from Person where id = :id").setLong("id",e.getId()).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression (Person)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression (Employee)s.createCriteria(Person.class).add(Restrictions.idEq(new Long(e.getId()))).uniqueResult() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression pLoad cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression pCriteria cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Expression pLoad cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression pGet cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Unmatched statement assertSame(pLoad,pCriteria); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement assertFalse(pLoad instanceof Employee); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted