File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java | |||
Method name: void testTransientEntityDeletionCascadingToDetachedAssociation()
|
Method name: void testCascadeSave()
|
|||
Number of AST nodes: 20 | Number of AST nodes: 18 | |||
1 | Session s = openSession(); ↵ | 1 | Session s = openSession();↵ | |
2 | Transaction t = s.beginTransaction(); ↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | Address address = new Address(); ↵ | 3 | Baz baz = new Baz();↵ | |
4 | address.setInfo( "123 Main St." );↵ | 4 | ↵ | |
5 | s.save( address );↵ | |||
6 | t.commit(); ↵ | 5 | List list = new ArrayList();↵ | |
7 | s.close();↵ | 6 | ↵ | |
8 | s = openSession();↵ | |||
9 | t = s.beginTransaction();↵ | |||
10 | Person p = new Person(↵ | 7 | list.add( new Fee() );↵ | |
11 | ); ↵ | 8 | list.add( new Fee() );↵ | |
12 | p.getAddresses().add( address ); ↵ | 9 | baz.setFees(list);↵ | |
13 | s.delete( p ); ↵ | 10 | s.save(baz);↵ | |
14 | t.commit(); ↵ | 11 | t.commit();↵ | |
15 | s.close();↵ | 12 | s.close();↵ | |
16 | ↵ | |||
17 | s = openSession(); ↵ | 13 | s = openSession();↵ | |
18 | t = s.beginTransaction(); ↵ | 14 | t = s.beginTransaction();↵ | |
19 | Long count = ( Long ) s.createQuery( "select count(*) from Address" ).list().get( 0 ); ↵ | 15 | baz = (Baz) s.load( Baz.class, baz.getCode() );↵ | |
20 | assertEquals( "delete not cascaded properly across transient entity", 0, count.longValue↵ | 16 | assertTrue( baz.getFees().size()==2 );↵ | |
17 | s.delete(baz);↵ | |||
21 | () ); ↵ | 18 | assertTrue( !s.iterate("from Fee fee").hasNext() );↵ | |
22 | t.commit(); ↵ | 19 | t.commit();↵ | |
23 | s.close(); | 20 |
| |
See real code fragment | See real code fragment |
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 in different classes having the same super class |
Number of node comparisons | 222 |
Number of mapped statements | 11 |
Number of unmapped statements in the first code fragment | 9 |
Number of unmapped statements in the second code fragment | 7 |
Time elapsed for statement mapping (ms) | 0.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Session s = openSession(); |
| 1 | Session s = openSession(); | |||||||||||||||||||||
2 | Transaction t = s.beginTransaction(); |
| 2 | Transaction t = s.beginTransaction(); | |||||||||||||||||||||
| 3 | Baz baz = new Baz(); | |||||||||||||||||||||||
3 | Address address = new Address(); | | |||||||||||||||||||||||
| 4 | List list = new ArrayList(); | |||||||||||||||||||||||
4 | address.setInfo("123 Main St."); |
| | ||||||||||||||||||||||
| 5 | list.add(new Fee()); | |||||||||||||||||||||||
| 6 | list.add(new Fee()); | |||||||||||||||||||||||
|
| 7 | baz.setFees(list); | ||||||||||||||||||||||
5 | s.save(address); |
| 8 | s.save(baz); | |||||||||||||||||||||
6 | t.commit(); | 9 | t.commit(); | ||||||||||||||||||||||
7 | s.close(); |
| 10 | s.close(); | |||||||||||||||||||||
8 | s = openSession(); |
| 11 | s = openSession(); | |||||||||||||||||||||
9 | t = s.beginTransaction(); |
| 12 | t = s.beginTransaction(); | |||||||||||||||||||||
10 | Person p = new Person(); | | |||||||||||||||||||||||
11 | p.getAddresses().add(address); | | |||||||||||||||||||||||
|
| 13 | baz = (Baz)s.load(Baz.class, baz.getCode()); | ||||||||||||||||||||||
12 | s.delete(p); |
| 15 | s.delete(baz); | |||||||||||||||||||||
|
| 16 | assertTrue(!s.iterate("from Fee fee").hasNext()); | ||||||||||||||||||||||
13 | t.commit(); | 17 | t.commit(); | ||||||||||||||||||||||
14 | s.close(); |
| | ||||||||||||||||||||||
15 | s = openSession(); |
| | ||||||||||||||||||||||
16 | t = s.beginTransaction(); |
| | ||||||||||||||||||||||
17 | Long count = (Long)s.createQuery("select count(*) from Address").list().get(0); | | |||||||||||||||||||||||
18 | assertEquals("delete not cascaded properly across transient entity", 0, count.longValue()); |
| 14 | assertTrue(baz.getFees().size() == 2); | |||||||||||||||||||||
19 | t.commit(); |
| | ||||||||||||||||||||||
20 | s.close(); |
| 18 | s.close(); |
Row | Violation |
---|---|
1 | Unmatched statement address.setInfo("123 Main St."); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
2 | Unmatched statement baz.setFees(list); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
3 | Expression address cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression baz cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Type org.hibernate.test.deletetransient.Address of variable address does not match with type org.hibernate.test.legacy.Baz of variable baz |
6 | Unmatched statement baz=(Baz)s.load(Baz.class,baz.getCode()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Expression p cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression baz cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Type org.hibernate.test.deletetransient.Person of variable p does not match with type org.hibernate.test.legacy.Baz of variable baz |
10 | Unmatched statement assertTrue(!s.iterate("from Fee fee").hasNext()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
11 | Unmatched statement s.close(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
12 | 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 | Unmatched statement t=s.beginTransaction(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
14 | Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
15 | Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
16 | Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) is a void method call, and thus it cannot be parameterized |
17 | Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized |
18 | Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
19 | Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
20 | Expression assertEquals("delete not cascaded properly across transient entity",0,count.longValue()) is a void method call, and thus it cannot be parameterized |
21 | Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized |
22 | Unmatched statement t.commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
23 | Clone fragment #1 returns variables s, t , while Clone fragment #2 returns variables s |