String resourceName = "org/hibernate/test/mappingexception/User.hbm.xml";
Configuration cfg = new Configuration();
cfg.addResource( resourceName );
try {
cfg.addResource( resourceName );
fail();
}
catch ( InvalidMappingException inv ) {
assertEquals( inv.getType(), "resource" );
assertEquals( inv.getPath(), resourceName );
assertClassAssignability( inv.getCause().getClass(), DuplicateMappingException.class );
}
Session s = openSession();
Transaction tx = s.beginTransaction();
VersionedEntity entity = new VersionedEntity( "test", "test" );
s.persist( entity );
s.merge( new VersionedEntity( "test", "test-2" ) );
try {
// control operation...
s.saveOrUpdate( new VersionedEntity( "test", "test-3" ) );
fail( "saveOrUpdate() should fail here" );
}
catch( NonUniqueObjectException expected ) {
// expected behavior
}
tx.commit();
s.close();
cleanup();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/mappingexception/MappingExceptionTest.java
|
|
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/ops/MergeTest.java
|
Method name: void testDuplicateMapping()
|
|
Method name: void testPersistThenMergeInSameTxnWithVersion()
|
Number of AST nodes: 6
|
|
Number of AST nodes: 11
|
|
1 | String resourceName = "org/hibernate/test/mappingexception/User.hbm.xml";↵ | | 1 | S↵
|
2 | Configuration cfg = new Configura↵ | | 2 | ession s = openSession();↵
|
3 | tion();
↵ | | 3 | Transaction tx = s.beginTransaction();↵
|
4 | cfg.addResource( resourceName );
↵ | | 4 | VersionedEntity entity = new VersionedEntity( "test", "test" );↵
|
5 | try {↵ | | 5 | ↵
|
6 | cfg.addResource( resourceName↵ | | 6 | s.persist( entity );↵
|
7 | );
↵ | | 7 | s.merge( new VersionedEntity( "test", "test-2" ) );↵
|
|
8 | fail();↵ | | 8 | ↵
|
9 | }↵ | | |
|
10 | catch ( InvalidMappingException inv ) {↵ | | |
|
11 | assertEquals( inv.getType()↵ | | 9 | try {↵
|
| | | 10 | // control operation...↵
|
12 | , "resource" );↵ | | 11 | s.saveOrUpdate( new VersionedEntity( "test", "tes↵
|
13 | assertEquals( inv.getP↵ | | 12 | t-3" ) );↵
|
14 | ath(), resourceName );
↵ | | 13 | fail( "saveOrUpdate() should fail here" );↵
|
15 | assertClassAssignability( inv.getCause().getClass(), DuplicateMappingException.class ↵ | | 14 | }↵
|
| | | 15 | catch( NonUniqueObjectException expected ) {↵
|
| | | 16 | // expected behavior↵
|
| | | 17 | }↵
|
|
| | | 18 | tx.commit();↵
|
16 | );
↵ | | 19 | s.close();↵
|
|
17 | } | | 20 | cleanup();
|
See real code fragment |
|
See real code fragment |
Summary
Number of common nesting structure subtrees | 0 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 0 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.1 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 1 |