Session s = openSession(); s.beginTransaction(); A a = new A(); a.setData( "Anna" ); s.save( a ); s.getTransaction().commit(); s.close(); // modify detached entity modifyEntity( a ); s = openSession(); s.beginTransaction(); A aLoaded = ( A ) s.load( A.class, new Long( a.getId() ) ); assertTrue( aLoaded instanceof HibernateProxy ); assertSame( aLoaded, s.merge( a ) ); s.getTransaction().commit(); s.close(); verifyModifications( a.getId() );
Session s = openSession(); Bar bar = new Bar(); s.save(bar); bar.setBarString("bar bar"); s.flush(); s.connection().commit(); s.close(); s = openSession(); FooProxy foo = (FooProxy) s.load( Foo.class, bar.getKey() ); assertTrue( "polymorphic", foo instanceof BarProxy ); assertTrue( "subclass property", ( (BarProxy) foo ).getBarString().equals( bar.getBarString() ) ); //System.out.println( s.print(foo) ); s.delete(foo); 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 testMultiPathMergeModifiedDetachedIntoProxy() Method name: void testPolymorphism()
Number of AST nodes: 16 Number of AST nodes: 15
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		
3
		A a = new A(
3
Bar bar = new Bar();
4
);
4
		s.save(bar);
5
		a.setData( "Anna" );
5
		bar.set
6
		s.save( a );
7
		s.getTransaction().commit();
8
		s.close();
9
		// modify detached entity
10
		modifyEntity( a );
11
		s = openSession();
12
		s.beginTransaction();
13
		A aLoaded = ( A 
6
BarString("bar bar");
7
		s.flush();
8
		s.connection().commit();
9
		s.close();
10
		s = openSession();
14
) s.load( A.class, new Long( a.getId() ) );
11
		FooProxy foo = (FooProxy) s.load( Foo.class, bar.getKey() );
15
		assertTrue( aLoaded instanceof HibernateProxy );
12
		assertTrue( "polymorphic", foo instanceof BarProxy );
16
		assertSame( aLoaded, s.merge( a ) );
13
		assert
17
		s.getTransaction().commit();
18
		s.close(
14
True( "subclass property", ( (BarProxy) foo ).getBarString().equals( bar.getBarString() ) );
15
		//System.out.println( s.print(foo) );
19
);
16
		s.delete(foo);
20
		verifyModifications( a.getId() 
17
		s.flush();
18
		s.connection().commit();
21
);
19
		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 comparisons186
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements9
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment6
    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
    Bar bar = new Bar();
    2
    s.beginTransaction();
                                                    
    3
    A a = new A();
                                  
    4
    a.setData("Anna");
                                              
    5
    s.save(a);
    5
    s.save(a);
    3
    s.save(bar);
    Differences
    Expression1Expression2Difference
    abarVARIABLE_NAME_MISMATCH
    org.hibernate.test.cascade.Aorg.hibernate.test.legacy.BarVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.legacy.Bar of variable bar
    • Make classes org.hibernate.test.cascade.A and org.hibernate.test.legacy.Bar extend a common superclass
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    3
    s.save(bar);
    6
    s.getTransaction().commit();
    6
    s.getTransaction().commit();
    6
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    getTransactionconnectionMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Transactionjava.sql.ConnectionVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    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
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    6
    s.connection().commit();
    7
    s.close();
    7
    s.close();
    7
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    7
    s.close();
    8
    modifyEntity(a);
    8
    modifyEntity(a);
    10
    assertTrue("polymorphic", foo instanceof BarProxy);
    Differences
    Expression1Expression2Difference
    modifyEntityassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    modifyEntity(a)assertTrue("polymorphic",foo instanceof BarProxy)ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("polymorphic",foo instanceof BarProxy) is a void method call, and thus it cannot be parameterized
    Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("polymorphic",foo instanceof BarProxy) is a void method call, and thus it cannot be parameterized
    10
    assertTrue("polymorphic", foo instanceof BarProxy);
    9
    s = openSession();
    9
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                          
    10
    s.beginTransaction();
                                                      
    11
    A aLoaded = (A)s.load(A.class, new Long(a.getId()));
                                                                                                              
    12
    assertTrue(aLoaded instanceof HibernateProxy);
    12
    assertTrue(aLoaded instanceof HibernateProxy);
    4
    bar.setBarString("bar bar");
    Differences
    Expression1Expression2Difference
    assertTruesetBarStringMETHOD_INVOCATION_NAME_MISMATCH
    barMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertTrue(aLoaded instanceof HibernateProxy) is a void method call, and thus it cannot be parameterized
    Expression bar.setBarString("bar bar") is a void method call, and thus it cannot be parameterized
    Expression assertTrue(aLoaded instanceof HibernateProxy) is a void method call, and thus it cannot be parameterized
    Expression bar.setBarString("bar bar") is a void method call, and thus it cannot be parameterized
    4
    bar.setBarString("bar bar");
    13
    assertSame(aLoaded, s.merge(a));
    13
    assertSame(aLoaded, s.merge(a));
    5
    s.flush();
    Differences
    Expression1Expression2Difference
    assertSameflushMETHOD_INVOCATION_NAME_MISMATCH
    assertSame(aLoaded,s.merge(a))s.flush()ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression assertSame(aLoaded,s.merge(a)) is a void method call, and thus it cannot be parameterized
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression assertSame(aLoaded,s.merge(a)) is a void method call, and thus it cannot be parameterized
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    5
    s.flush();
                                          
    8
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    s = openSession();
                                                                                                                      
    9
    FooProxy foo = (FooProxy)s.load(Foo.class, bar.getKey());
                                        
    12
    s.delete(foo);
                                
    13
    s.flush();
    14
    s.getTransaction().commit();
    14
    s.getTransaction().commit();
    14
    s.connection().commit();
    Differences
    Expression1Expression2Difference
    getTransactionconnectionMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Transactionjava.sql.ConnectionVARIABLE_TYPE_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    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
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    14
    s.connection().commit();
    15
    s.close();
    15
    s.close();
    15
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    • Make classes org.hibernate.Session and org.hibernate.classic.Session extend a common superclass
    15
    s.close();
    16
    verifyModifications(a.getId());
    16
    verifyModifications(a.getId());
    11
    assertTrue("subclass property", ((BarProxy)foo).getBarString().equals(bar.getBarString()));
    Differences
    Expression1Expression2Difference
    verifyModificationsassertTrueMETHOD_INVOCATION_NAME_MISMATCH
    verifyModifications(a.getId())assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString()))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression verifyModifications(a.getId()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression verifyModifications(a.getId()) is a void method call, and thus it cannot be parameterized
    Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    11
    assertTrue("subclass property", ((BarProxy)foo).getBarString().equals(bar.getBarString()));
    Precondition Violations (28)
    Row Violation
    1Type org.hibernate.test.cascade.A of variable a does not match with type org.hibernate.test.legacy.Bar of variable bar
    2Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    3Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    4Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    5Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    6Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    7Expression assertTrue("polymorphic",foo instanceof BarProxy) is a void method call, and thus it cannot be parameterized
    8Expression modifyEntity(a) is a void method call, and thus it cannot be parameterized
    9Expression assertTrue("polymorphic",foo instanceof BarProxy) is a void method call, and thus it cannot be parameterized
    10Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Expression assertTrue(aLoaded instanceof HibernateProxy) is a void method call, and thus it cannot be parameterized
    12Expression bar.setBarString("bar bar") is a void method call, and thus it cannot be parameterized
    13Expression assertTrue(aLoaded instanceof HibernateProxy) is a void method call, and thus it cannot be parameterized
    14Expression bar.setBarString("bar bar") is a void method call, and thus it cannot be parameterized
    15Expression assertSame(aLoaded,s.merge(a)) is a void method call, and thus it cannot be parameterized
    16Expression s.flush() is a void method call, and thus it cannot be parameterized
    17Expression assertSame(aLoaded,s.merge(a)) is a void method call, and thus it cannot be parameterized
    18Expression s.flush() is a void method call, and thus it cannot be parameterized
    19Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    21Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    22Type org.hibernate.Session of variable s does not match with type org.hibernate.classic.Session of variable s
    23Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    24Expression verifyModifications(a.getId()) is a void method call, and thus it cannot be parameterized
    25Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized
    26Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    27Expression verifyModifications(a.getId()) is a void method call, and thus it cannot be parameterized
    28Expression assertTrue("subclass property",((BarProxy)foo).getBarString().equals(bar.getBarString())) is a void method call, and thus it cannot be parameterized