Session s = openSession(); s.beginTransaction(); PropertyValue redValue = new StringPropertyValue( "red" ); PropertyValue lonliestNumberValue = new IntegerPropertyValue( 1 ); Long id; PropertySet ps = new PropertySet( "my properties" ); ps.setSomeSpecificProperty( redValue ); ps.getGeneralProperties().put( "the lonliest number", lonliestNumberValue ); ps.getGeneralProperties().put( "i like", new StringPropertyValue( "pina coladas" ) ); ps.getGeneralProperties().put( "i also like", new StringPropertyValue( "getting caught in the rain" ) ); s.save( ps ); s.getTransaction().commit(); id = ps.getId(); s.clear(); s.beginTransaction(); // TODO : setEntity() currently will not work here, but that would be *very* nice // does not work because the corresponding EntityType is then used as the "bind type" rather // than the "discovered" AnyType... s.createQuery( "from PropertySet p where p.someSpecificProperty = :ssp" ).setParameter( "ssp", redValue ).list(); s.createQuery( "from PropertySet p where p.someSpecificProperty.id is not null" ).list(); s.createQuery( "from PropertySet p join p.generalProperties gp where gp.id is not null" ).list(); s.delete( s.load( PropertySet.class, id ) ); s.getTransaction().commit(); s.close();
Session s = openSession(); Baz baz = new Baz(); List l = new ArrayList(); baz.setStringList(l); l.add("foo"); Serializable id = s.save(baz); l.add("bar"); s.flush(); l.add("baz"); s.flush(); s.connection().commit(); s.close(); s = openSession(); baz = (Baz) s.load(Baz.class, id); assertTrue( baz.getStringList().size()==3 && baz.getStringList().contains("bar") ); s.delete(baz); 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/hql/ASTParserLoadingTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java
Method name: void testAnyMappingReference() Method name: void testLateCollectionAdd()
Number of AST nodes: 21 Number of AST nodes: 19
1
Session s = openSession();
1
Session s = openSession();
2
		s.beginTransaction();
2
		
3
		PropertyValue redValue = new StringPropertyValue( "red" );
4
		PropertyValue lonliestNumberValue = new IntegerPropertyValue( 1 );
5
		Long id;
6
		PropertySet ps = new PropertySet( "my properties" 
3
Baz baz = new Baz();
7
);
4
		List l = new ArrayList();
8
		ps.setSomeSpecificProperty( redValue );
5
		baz.setS
9
		ps.getGeneralProperties().put( "the lonliest number", lonliestNumberValue );
10
		ps.getGen
6
tringList(l);
7
		l.add("foo");
11
eralProperties().put( "i like", new StringPropertyValue( "pina coladas" ) 
8
		Serializable id = s.save(baz);
12
);
9
		l.add("bar");
13
		ps.getGeneralProperties().put( "i also like", new StringPropertyValue( "getting caught in the rain" ) );
10
		s.
14
		s.save( ps 
11
flush();
12
		l.add("baz");
15
);
13
		s.flush();
16
		s.getTransaction().commit();
14
		s.connection().commit();
17
		id = ps.getId();
15
		
18
		s.clear();
16
s.close();
19
		s.beginTransaction();
17
		s = openSession();
20
		// TODO : setEntity() currently will not work here, but that would be *very* nice
18
		
21
		// does not work because the corresponding EntityType is then used as the "bind type" rather
22
		// than the "discovered" AnyType...
23
		s.createQuery( "from PropertySet p where p.someSpecificProperty = :ssp" ).setParameter( "ssp", redValue ).list();
24
		s.createQuery( "from PropertySet p where p.someSpecificProperty.id is not null" ).list();
25
		s.createQuery( "from PropertySet p join p.generalProperties gp where gp.id is not null" ).list(
19
baz = (Baz) s.load(Baz.class, id);
26
);
20
		assertTrue( baz.getStringList().size()==3 && baz.getStringList().contains("bar") );
27
		s.delete( s.load( PropertySet.class, id ) 
21
		s.delete(baz);
28
);
22
		s.flush();
29
		s.getTransaction().commit();
23
		s.connection().commit();
30
		s.close();
24
		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 comparisons399
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment16
    Number of unmapped statements in the second code fragment14
    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();
    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
    Baz baz = new Baz();
    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
    List l = new ArrayList();
    3
    PropertyValue redValue = new StringPropertyValue("red");
    3
    PropertyValue redValue = new StringPropertyValue("red");
    Preondition Violations
    Unmatched statement PropertyValue redValue=new StringPropertyValue("red"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                      
                                                    
    4
    baz.setStringList(l);
    Preondition Violations
    Unmatched statement baz.setStringList(l); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4
    baz.setStringList(l);
    4
    PropertyValue lonliestNumberValue = new IntegerPropertyValue(1);
    4
    PropertyValue lonliestNumberValue = new IntegerPropertyValue(1);
    Preondition Violations
    Unmatched statement PropertyValue lonliestNumberValue=new IntegerPropertyValue(1); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                                                      
                                    
    5
    l.add("foo");
    5
    Long id;
                          
                                                                  
    6
    Serializable id = s.save(baz);
    Preondition Violations
    Unmatched statement Serializable id=s.save(baz); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    Serializable id = s.save(baz);
    6
    PropertySet ps = new PropertySet("my properties");
    6
    PropertySet ps = new PropertySet("my properties");
    Preondition Violations
    Unmatched statement PropertySet ps=new PropertySet("my properties"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                          
                                    
    7
    l.add("bar");
    7
    ps.setSomeSpecificProperty(redValue);
    7
    ps.setSomeSpecificProperty(redValue);
    Preondition Violations
    Unmatched statement ps.setSomeSpecificProperty(redValue); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                    
    8
    ps.getGeneralProperties().put("the lonliest number", lonliestNumberValue);
                                                                                                                                                            
    9
    ps.getGeneralProperties().put("i like", new StringPropertyValue("pina coladas"));
                                                                                                                                                                          
    10
    ps.getGeneralProperties().put("i also like", new StringPropertyValue("getting caught in the rain"));
                                                                                                                                                                                                                  
    11
    s.save(ps);
    11
    s.save(ps);
    Preondition Violations
    Unmatched statement s.save(ps); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                  
    12
    s.getTransaction().commit();
    12
    s.getTransaction().commit();
    11
    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
    11
    s.connection().commit();
    13
    id = ps.getId();
                                        
    14
    s.clear();
    14
    s.clear();
    8
    s.flush();
    Differences
    Expression1Expression2Difference
    clearflushMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.clear() 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
    8
    s.flush();
                                    
    9
    l.add("baz");
    15
    s.beginTransaction();
    15
    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
                                                      
    16
    s.createQuery("from PropertySet p where p.someSpecificProperty = :ssp").setParameter("ssp", redValue).list();
    16
    s.createQuery("from PropertySet p where p.someSpecificProperty = :ssp").setParameter("ssp", redValue).list();
    Preondition Violations
    Unmatched statement s.createQuery("from PropertySet p where p.someSpecificProperty = :ssp").setParameter("ssp",redValue).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                                                    
    17
    s.createQuery("from PropertySet p where p.someSpecificProperty.id is not null").list();
    17
    s.createQuery("from PropertySet p where p.someSpecificProperty.id is not null").list();
    Preondition Violations
    Unmatched statement s.createQuery("from PropertySet p where p.someSpecificProperty.id is not null").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                          
    18
    s.createQuery("from PropertySet p join p.generalProperties gp where gp.id is not null").list();
    18
    s.createQuery("from PropertySet p join p.generalProperties gp where gp.id is not null").list();
    Preondition Violations
    Unmatched statement s.createQuery("from PropertySet p join p.generalProperties gp where gp.id is not null").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                          
    19
    s.delete(s.load(PropertySet.class, id));
    19
    s.delete(s.load(PropertySet.class, id));
    10
    s.flush();
    Differences
    Expression1Expression2Difference
    deleteflushMETHOD_INVOCATION_NAME_MISMATCH
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    s.delete(s.load(PropertySet.class,id))s.flush()ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression s.delete(s.load(PropertySet.class,id)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(s.load(PropertySet.class,id)) 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 s.delete(s.load(PropertySet.class,id)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression s.delete(s.load(PropertySet.class,id)) 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
    10
    s.flush();
    20
    s.getTransaction().commit();
    20
    s.getTransaction().commit();
    Preondition Violations
    Unmatched statement s.getTransaction().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                    
    21
    s.close();
    21
    s.close();
    12
    s.close();
    Differences
    Expression1Expression2Difference
    org.hibernate.Sessionorg.hibernate.classic.SessionSUBCLASS_TYPE_MISMATCH
    12
    s.close();
                                            
    13
    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
    13
    s = openSession();
                                                                        
    14
    baz = (Baz)s.load(Baz.class, id);
                                                                                                                                                                                  
    15
    assertTrue(baz.getStringList().size() == 3 && baz.getStringList().contains("bar"));
                                        
    16
    s.delete(baz);
                                
    17
    s.flush();
                                                            
    18
    s.connection().commit();
                                
    19
    s.close();
    Precondition Violations (30)
    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 PropertyValue redValue=new StringPropertyValue("red"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Unmatched statement baz.setStringList(l); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    4Unmatched statement PropertyValue lonliestNumberValue=new IntegerPropertyValue(1); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    5Unmatched statement Serializable id=s.save(baz); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement PropertySet ps=new PropertySet("my properties"); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    7Unmatched statement ps.setSomeSpecificProperty(redValue); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    8Unmatched statement s.save(ps); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    9Expression s.getTransaction() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    10Expression s.connection() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Type org.hibernate.Transaction of variable s.getTransaction() does not match with type java.sql.Connection of variable s.connection()
    12Expression s.clear() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression s.clear() is a void method call, and thus it cannot be parameterized
    15Expression s.flush() is a void method call, and thus it cannot be parameterized
    16Unmatched statement s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17Unmatched statement s.createQuery("from PropertySet p where p.someSpecificProperty = :ssp").setParameter("ssp",redValue).list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    18Unmatched statement s.createQuery("from PropertySet p where p.someSpecificProperty.id is not null").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19Unmatched statement s.createQuery("from PropertySet p join p.generalProperties gp where gp.id is not null").list(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Expression s.delete(s.load(PropertySet.class,id)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    21Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    22Expression s.delete(s.load(PropertySet.class,id)) is a void method call, and thus it cannot be parameterized
    23Expression s.flush() is a void method call, and thus it cannot be parameterized
    24Expression s.delete(s.load(PropertySet.class,id)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    25Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression s.delete(s.load(PropertySet.class,id)) is a void method call, and thus it cannot be parameterized
    27Expression s.flush() is a void method call, and thus it cannot be parameterized
    28Unmatched statement s.getTransaction().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    29Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    30Clone fragment #1 returns variable s with type org.hibernate.Session , while Clone fragment #2 returns variable s with type org.hibernate.classic.Session