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();
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();
s.update( a );
s.getTransaction().commit();
s.close();
verifyModifications( a.getId() );
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/cascade/MultiPathCascadeTest.java
|
Method name: void testMultiPathGetAndModify()
|
|
Method name: void testMultiPathUpdateModifiedDetached()
|
Number of AST nodes: 14
|
|
Number of AST nodes: 14
|
|
1 | Session s = openSession();↵ | | 1 | Session s = openSession();↵
|
2 | s.beginTransaction();↵ | | 2 | s.beginTransaction();↵
|
3 | A a = new A();↵ | | 3 | A a = new A();↵
|
4 | a.setData( "Anna" );↵ | | 4 | a.setData( "Anna" );↵
|
5 | s.save( a );↵ | | 5 | s.save( a );↵
|
6 | s.getTransaction().commit();↵ | | 6 | s.getTransaction().commit();↵
|
7 | s.close();↵ | | 7 | s.close();↵
|
|
8 | s = openSession();↵ | | 8 | ↵
|
9 | s.beginTransaction();↵ | | |
|
10 | // retrieve the previously saved instance from the database, and update it↵ | | |
|
11 | a = ( A ) s.get( A.class, new Long( a.getId() ) );↵ | | |
|
12 | modifyEntity↵ | | 9 | // modify detached entity↵
|
| | | 10 | modifyEntity( a );↵
|
|
| | | 11 | s = openSession();↵
|
| | | 12 | s.beginTransaction();↵
|
13 | ( a );↵ | | 13 | s.update( a );↵
|
14 | s.getTransaction().commit();↵ | | 14 | s.getTransaction().commit();↵
|
15 | s.close();↵ | | 15 | s.close();↵
|
|
16 | verifyModifications( a.getId() ); | | 16 | verifyModifications( a.getId() );
|
See real code fragment |
|
See real code fragment |
Summary
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 46 |
-
{Non-refactorable}
Mapping Summary
Number of mapped statements | 13 |
Number of unmapped statements in the first code fragment | 1 |
Number of unmapped statements in the second code fragment | 1 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 2 |
Mapped Statements
ID |
Statement |
|
ID |
Statement |
1 | Session s = openSession(); | | 1 | Session s = openSession(); |
2 | s.beginTransaction(); | | 2 | s.beginTransaction(); |
3 | A a = new A(); | | 3 | A a = new A(); |
4 | a.setData("Anna"); | | 4 | a.setData("Anna"); |
5 | s.save(a); | | 5 | s.save(a); |
6 | s.getTransaction().commit(); | | 6 | s.getTransaction().commit(); |
7 | s.close(); | | 7 | s.close(); |
8 | s = openSession(); | | 9 | s = openSession(); |
9 | s.beginTransaction(); | | 10 | s.beginTransaction(); |
10 | a = (A)s.get(A.class, new Long(a.getId())); | | | |
11 | modifyEntity(a); | | 8 | modifyEntity(a); |
| | | 11 | s.update(a); |
12 | s.getTransaction().commit(); | | 12 | s.getTransaction().commit(); |
13 | s.close(); | | 13 | s.close(); |
14 | verifyModifications(a.getId()); | | 14 | verifyModifications(a.getId()); |
Precondition Violations (2)
Row |
Violation |
1 | 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 |
2 | Clone fragment #1 returns variables a, s , while Clone fragment #2 returns variables a, s |