final StatefulInterceptor statefulInterceptor = new StatefulInterceptor(); Session s = openSession( statefulInterceptor ); statefulInterceptor.setSession(s); Transaction t = s.beginTransaction(); User u = new User("Gavin", "nivag"); s.persist(u); u.setPassword("vagni"); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); List logs = s.createCriteria(Log.class).list(); assertEquals( 2, logs.size() ); s.delete(u); s.createQuery( "delete from Log" ).executeUpdate(); t.commit(); s.close();
Customer cust = new Customer(); cust.setCustomerId("xyz123"); cust.setName("Matt"); Session s = openSession(); Transaction t = s.beginTransaction(); s.persist(cust); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list(); //List results = s.createQuery("from Customer cust left join fetch cust.billingAddress left join fetch cust.shippingAddress").list(); cust = (Customer) results.get(0); assertNull( cust.getShippingAddress() ); assertNull( cust.getBillingAddress() ); s.delete(cust); 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/interceptor/InterceptorTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/typedonetoone/TypedOneToOneTest.java
Method name: void testStatefulIntercept() Method name: void testCreateQueryNull()
Number of AST nodes: 17 Number of AST nodes: 17
1
final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
2
		Session s = openSession( statefulInterceptor );
3
		statefulInterceptor.set
1
Customer cust = new Customer();
2
		cust.setCustomerId("xyz123");
3
		cust.setName("Matt");
4
		
4
Session(s);
5
		Session s = openSession();
5
		Transaction t = s.beginTransaction();
6
		Transaction t = s.beginTransaction();
6
		User u = new User("Gavin", "nivag");
7
		
7
		s.persist(u);
8
		u.setPassword("vagni");
8
s.persist(cust);
9
		t.commit();
9
		t.commit();
10
		s.close();
10
		s.close();
11
		
11
		s = openSession();
12
		s = openSession();
12
		t = s.beginTransaction();
13
		t = s.beginTransaction();
13
		List logs = s.createCriteria(Log.class).list();
14
		List results = s.create
14
		assertEquals( 2, logs.size() );
15
		s.delete(u);
16
		s.createQuery( "delete from Log" ).executeUpdate(
15
Query("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list();
16
		//List results = s.createQuery("from Customer cust left join fetch cust.billingAddress left join fetch cust.shippingAddress").list();
17
		cust = (Customer) results.get(0);
18
		assertNull( cust.getShippingAddress() );
19
		assertNull( cust.getBillingAddress() );
17
);
20
		s.delete(cust);
18
		t.commit();
21
		t.commit();
19
		s.close();
22
		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 comparisons178
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements11
    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
    Customer cust = new Customer();
    1
    final StatefulInterceptor statefulInterceptor = new StatefulInterceptor();
                                                                                                                                                          
                                                                    
    2
    cust.setCustomerId("xyz123");
    Preondition Violations
    Unmatched statement cust.setCustomerId("xyz123"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2
    cust.setCustomerId("xyz123");
                                                    
    3
    cust.setName("Matt");
    Preondition Violations
    Unmatched statement cust.setName("Matt"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3
    cust.setName("Matt");
    2
    Session s = openSession(statefulInterceptor);
    2
    Session s = openSession(statefulInterceptor);
    4
    Session s = openSession();
    Differences
    Expression1Expression2Difference
    openSession(statefulInterceptor)openSession()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4
    Session s = openSession();
    3
    statefulInterceptor.setSession(s);
    3
    statefulInterceptor.setSession(s);
    Preondition Violations
    Unmatched statement statefulInterceptor.setSession(s); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                              
    4
    Transaction t = s.beginTransaction();
    5
    Transaction t = s.beginTransaction();
    5
    User u = new User("Gavin", "nivag");
    5
    User u = new User("Gavin", "nivag");
    Preondition Violations
    Unmatched statement User u=new User("Gavin","nivag"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                            
    6
    s.persist(u);
    6
    s.persist(u);
    6
    s.persist(cust);
    Differences
    Expression1Expression2Difference
    ucustVARIABLE_NAME_MISMATCH
    org.hibernate.test.interceptor.Userorg.hibernate.test.typedonetoone.CustomerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.interceptor.User of variable u does not match with type org.hibernate.test.typedonetoone.Customer of variable cust
    • Make classes org.hibernate.test.interceptor.User and org.hibernate.test.typedonetoone.Customer extend a common superclass
    6
    s.persist(cust);
    7
    u.setPassword("vagni");
    7
    u.setPassword("vagni");
    Preondition Violations
    Unmatched statement u.setPassword("vagni"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                        
    8
    t.commit();
    7
    t.commit();
    9
    s.close();
    8
    s.close();
    10
    s = openSession();
    9
    s = openSession();
    11
    t = s.beginTransaction();
    10
    t = s.beginTransaction();
                                                                                                                                                                                                                                                                  
    11
    List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list();
    Preondition Violations
    Unmatched statement List results=s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11
    List results = s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list();
                                                                        
    12
    cust = (Customer)results.get(0);
    Preondition Violations
    Unmatched statement cust=(Customer)results.get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12
    cust = (Customer)results.get(0);
    12
    List logs = s.createCriteria(Log.class).list();
    12
    List logs = s.createCriteria(Log.class).list();
    Preondition Violations
    Unmatched statement List logs=s.createCriteria(Log.class).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                      
    13
    assertEquals(2, logs.size());
    13
    assertEquals(2, logs.size());
    13
    assertNull(cust.getShippingAddress());
    Differences
    Expression1Expression2Difference
    assertEqualsassertNullMETHOD_INVOCATION_NAME_MISMATCH
    assertEquals(2,logs.size())assertNull(cust.getShippingAddress())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    13
    assertNull(cust.getShippingAddress());
                                                                                      
    14
    assertNull(cust.getBillingAddress());
    14
    s.delete(u);
    14
    s.delete(u);
    15
    s.delete(cust);
    Differences
    Expression1Expression2Difference
    ucustVARIABLE_NAME_MISMATCH
    org.hibernate.test.interceptor.Userorg.hibernate.test.typedonetoone.CustomerVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.hibernate.test.interceptor.User of variable u does not match with type org.hibernate.test.typedonetoone.Customer of variable cust
    • Make classes org.hibernate.test.interceptor.User and org.hibernate.test.typedonetoone.Customer extend a common superclass
    15
    s.delete(cust);
    15
    s.createQuery("delete from Log").executeUpdate();
    15
    s.createQuery("delete from Log").executeUpdate();
    Preondition Violations
    Unmatched statement s.createQuery("delete from Log").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                              
    16
    t.commit();
    16
    t.commit();
    17
    s.close();
    17
    s.close();
    Precondition Violations (21)
    Row Violation
    1Unmatched statement cust.setCustomerId("xyz123"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement cust.setName("Matt"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Expression openSession(statefulInterceptor) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression openSession() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Unmatched statement statefulInterceptor.setSession(s); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement User u=new User("Gavin","nivag"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7Type org.hibernate.test.interceptor.User of variable u does not match with type org.hibernate.test.typedonetoone.Customer of variable cust
    8Unmatched statement u.setPassword("vagni"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    9Unmatched statement List results=s.createQuery("from Customer cust left join fetch cust.billingAddress where cust.customerId='xyz123'").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement cust=(Customer)results.get(0); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement List logs=s.createCriteria(Log.class).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    15Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    16Expression assertEquals(2,logs.size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression assertNull(cust.getShippingAddress()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression assertEquals(2,logs.size()) is a void method call, and thus it cannot be parameterized
    19Expression assertNull(cust.getShippingAddress()) is a void method call, and thus it cannot be parameterized
    20Type org.hibernate.test.interceptor.User of variable u does not match with type org.hibernate.test.typedonetoone.Customer of variable cust
    21Unmatched statement s.createQuery("delete from Log").executeUpdate(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted