Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); // retrieve the previously saved instance from the database, and update it a = ( A ) s.get( A.class, new Long( a.getId() ) ); modifyEntity( a ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() );
Session s = openSession(); Foo foo = new Foo(); s.save(foo); s.flush(); s.connection().commit(); s.close(); s = openSession(); Foo foo2 = new Foo(); s.load( foo2, foo.getKey() ); // There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15 assertTrue( "create", foo.equalsFoo(foo2) ); s.delete(foo2); s.flush(); s.connection().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/cascade/MultiPathCascadeTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
Method name: void testMultiPathGetAndModify() Method name: void testCreate()
Number of AST nodes: 14 Number of AST nodes: 14
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		
3
		A a = new A();
3
Foo foo = new Foo();
4
		a.setData( "Anna" );
4
		s.s
5
		s.save( a );
6
		s.getTransa
5
ave(foo);
6
		s.flush();
7
ction().commit();
7
		s.connection().commit();
8
		s.close();
8
		s.close();
9
		s = openSession();
9
		s = openSession();
10
		s.beginTransaction();
10
		
11
		// retrieve the previously saved instance from the database, and update it
12
		a = ( A ) s.get( A.class, new Long( a.getId() ) );
13
		modifyEntity( a );
14
		s.getTransaction().commit();
15
		s.close();
16
		verifyModifications( a.getId() 
11
Foo foo2 = new Foo();
12
		s.load( foo2, foo.getKey() );
13
		// There is an interbase bug that causes null integers to return as 0, also numeric precision is <= 15
14
		assertTrue( "create", foo.equalsFoo(foo2) );
15
		s.delete(foo2);
16
		s.flush();
17
		s.connection().commit();
17
);
18
		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 comparisons148
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment6
    Number of unmapped statements in the second code fragment6
    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();
    1
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    1
    Session s = openSession();
                                              
    2
    Foo foo = new Foo();
    2
    s.beginTransaction();
    2
    s.beginTransaction();
    Preondition Violations
    Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                    
    3
    A a = new A();
    3
    A a = new A();
    Preondition Violations
    Unmatched statement A a=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                  
    4
    a.setData("Anna");
    4
    a.setData("Anna");
    Preondition Violations
    Unmatched statement a.setData("Anna"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                              
    5
    s.save(a);
    5
    s.save(a);
    3
    s.save(foo);
    Differences
    Expression1Expression2Difference
    afooVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Aorg.hibernate.test.legacy.FooVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.legacy.Foo of variable foo
    • Make classes org.hibernate.test.cascade.A and org.hibernate.test.legacy.Foo extend a common superclass
    3
    s.save(foo);
                              
    4
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4
    s.flush();
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    5
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    getTransactionconnectionMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Transactionjava.sql.ConnectionVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    • Make classes org.hibernate.Transaction and java.sql.Connection extend a common superclass
    5
    s.connection().commit();
    7
    s.close();
    7
    s.close();
    6
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    6
    s.close();
    8
    s = openSession();
    8
    s = openSession();
    7
    s = openSession();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    7
    s = openSession();
                                                
    8
    Foo foo2 = new Foo();
                                                              
    9
    s.load(foo2, foo.getKey());
    Preondition Violations
    Unmatched statement s.load(foo2,foo.getKey()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9
    s.load(foo2, foo.getKey());
    9
    s.beginTransaction();
    9
    s.beginTransaction();
    Preondition Violations
    Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                    
    10
    a = (A)s.get(A.class, new Long(a.getId()));
    10
    a = (A)s.get(A.class, new Long(a.getId()));
    Preondition Violations
    Unmatched statement a=(A)s.get(A.class,new Long(a.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                            
    11
    modifyEntity(a);
    11
    modifyEntity(a);
    10
    assertTrue("create", foo.equalsFoo(foo2));
    Differences
    Expression1Expression2Difference
    modifyEntityassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    modifyEntity(a)assertTrue("create",foo.equalsFoo(foo2))TYPE_COMPATIBLE_REPLACEMENT
    modifyEntity(a)assertTrue("create",foo.equalsFoo(foo2))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method modifyEntity
    Expression assertTrue("create",foo.equalsFoo(foo2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("create",foo.equalsFoo(foo2)) is a void method call, and thus it cannot be parameterized
    Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method modifyEntity
    Expression assertTrue("create",foo.equalsFoo(foo2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("create",foo.equalsFoo(foo2)) is a void method call, and thus it cannot be parameterized
    10
    assertTrue("create", foo.equalsFoo(foo2));
                                          
    11
    s.delete(foo2);
    Preondition Violations
    Unmatched statement s.delete(foo2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    s.delete(foo2);
                                
    12
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    s.flush();
    12
    s.getTransaction().commit();
    12
    s.getTransaction().commit();
    13
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    getTransactionconnectionMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Transactionjava.sql.ConnectionVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    • Make classes org.hibernate.Transaction and java.sql.Connection extend a common superclass
    13
    s.connection().commit();
    13
    s.close();
    13
    s.close();
    14
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    14
    s.close();
    14
    verifyModifications(a.getId());
                                                                          
    Precondition Violations (25)
    Row Violation
    1Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement A a=new A(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement a.setData("Anna"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.legacy.Foo of variable foo
    5Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    9Unmatched statement s.load(foo2,foo.getKey()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement a=(A)s.get(A.class,new Long(a.getId())); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression assertTrue("create",foo.equalsFoo(foo2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    15Expression assertTrue("create",foo.equalsFoo(foo2)) is a void method call, and thus it cannot be parameterized
    16Expression modifyEntity(a) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression assertTrue("create",foo.equalsFoo(foo2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    19Expression assertTrue("create",foo.equalsFoo(foo2)) is a void method call, and thus it cannot be parameterized
    20Unmatched statement s.delete(foo2); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    25Clone fragment #1 returns variable s with type org.hibernate.Session , while Clone fragment #2 returns variable s with type org.hibernate.classic.Session