File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/BidirectionalOneToManyCascadeTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/legacy/FooBarTest.java | |||
Method name: void testSaveParentWithOrphanDeleteChild()
|
Method name: void testCascadeSave()
|
|||
Number of AST nodes: 17 | Number of AST nodes: 18 | |||
1 | Session session = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | Transaction txn = session.beginTransaction();↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | Parent parent = new Parent();↵ | 3 | Baz baz = new ↵ | |
4 | DeleteOrphanChild child = new DeleteOrphanChild();↵ | |||
5 | child.setParent( parent );↵ | |||
6 | parent.setDeleteOrphanChildren( Collections.singleton( child ) );↵ | |||
7 | session.save( parent ↵ | 4 | Baz();↵ | |
5 | List list = new ArrayList();↵ | |||
6 | list.add( new Fee() );↵ | |||
7 | list.add( new Fee() );↵ | |||
8 | baz.setFees(list);↵ | |||
8 | );↵ | 9 | s.save(baz);↵ | |
9 | txn.commit();↵ | 10 | t.commit();↵ | |
10 | session.close();↵ | 11 | s.close();↵ | |
11 | session = openSession();↵ | 12 | s = openSession();↵ | |
12 | txn = session.beginTransaction();↵ | 13 | t = s.beginTransaction();↵ | |
13 | parent = ( Parent ) session.get( Parent.class, parent.getId() );↵ | 14 | baz = (Baz) s.load( Baz.class, baz.getCode() );↵ | |
14 | assertEquals( 0, parent.getChildren().size() );↵ | 15 | assertTrue( baz.getFees().size()==2 );↵ | |
15 | assertEquals( 1, parent.getDeleteOrphanChildren().size() );↵ | 16 | ↵ | |
16 | session.delete( parent↵ | 17 | s.delete(baz);↵ | |
17 | );↵ | 18 | assertTrue( !s.iterate("from Fee fee").hasNext() );↵ | |
18 | txn.commit();↵ | 19 | t.commit();↵ | |
19 | session.close(); | 20 | s.close(); | |
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 | 234 |
Number of mapped statements | 11 |
Number of unmapped statements in the first code fragment | 6 |
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 session = openSession(); |
| 1 | Session s = openSession(); | |||||||||||||||||||||
2 | Transaction txn = session.beginTransaction(); |
| 2 | Transaction t = s.beginTransaction(); | |||||||||||||||||||||
| 3 | Baz baz = new Baz(); | |||||||||||||||||||||||
3 | Parent parent = new Parent(); | | |||||||||||||||||||||||
| 4 | List list = new ArrayList(); | |||||||||||||||||||||||
4 | DeleteOrphanChild child = new DeleteOrphanChild(); | | |||||||||||||||||||||||
| 5 | list.add(new Fee()); | |||||||||||||||||||||||
5 | child.setParent(parent); |
| | ||||||||||||||||||||||
| 6 | list.add(new Fee()); | |||||||||||||||||||||||
6 | parent.setDeleteOrphanChildren(Collections.singleton(child)); |
| | ||||||||||||||||||||||
|
| 7 | baz.setFees(list); | ||||||||||||||||||||||
7 | session.save(parent); |
| 8 | s.save(baz); | |||||||||||||||||||||
8 | txn.commit(); |
| 9 | t.commit(); | |||||||||||||||||||||
9 | session.close(); |
| 10 | s.close(); | |||||||||||||||||||||
10 | session = openSession(); |
| 11 | s = openSession(); | |||||||||||||||||||||
11 | txn = session.beginTransaction(); |
| 12 | t = s.beginTransaction(); | |||||||||||||||||||||
12 | parent = (Parent)session.get(Parent.class, parent.getId()); |
| | ||||||||||||||||||||||
|
| 13 | baz = (Baz)s.load(Baz.class, baz.getCode()); | ||||||||||||||||||||||
13 | assertEquals(0, parent.getChildren().size()); |
| 14 | assertTrue(baz.getFees().size() == 2); | |||||||||||||||||||||
14 | assertEquals(1, parent.getDeleteOrphanChildren().size()); | | |||||||||||||||||||||||
15 | session.delete(parent); |
| 15 | s.delete(baz); | |||||||||||||||||||||
|
| 16 | assertTrue(!s.iterate("from Fee fee").hasNext()); | ||||||||||||||||||||||
16 | txn.commit(); |
| 17 | t.commit(); | |||||||||||||||||||||
17 | session.close(); |
| 18 | s.close(); |
Row | Violation |
---|---|
1 | Unmatched statement child.setParent(parent); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
2 | Unmatched statement parent.setDeleteOrphanChildren(Collections.singleton(child)); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
3 | Unmatched statement baz.setFees(list); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
4 | Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz |
5 | Unmatched statement parent=(Parent)session.get(Parent.class,parent.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
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 assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized |
10 | Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized |
11 | Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression assertTrue(baz.getFees().size() == 2) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized |
14 | Expression assertTrue(baz.getFees().size() == 2) is a void method call, and thus it cannot be parameterized |
15 | Type org.hibernate.test.cascade.Parent of variable parent does not match with type org.hibernate.test.legacy.Baz of variable baz |
16 | 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 |
17 | Clone fragment #1 returns variable session with type org.hibernate.Session , while Clone fragment #2 returns variable s with type org.hibernate.classic.Session |