File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/propertyref/basic/PropertyRefTest.java | File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/usercollection/basic/UserCollectionTypeTest.java | |||
Method name: void testManyToManyPropertyRef()
|
Method name: void testBasicOperation()
|
|||
Number of AST nodes: 30 | Number of AST nodes: 27 | |||
1 | Session s = openSession(); ↵ | 1 | Session s = openSession();↵ | |
2 | Transaction t = s.beginTransaction(); ↵ | 2 | Transaction t = s.beginTransaction();↵ | |
3 | Person p = new Person(); ↵ | 3 | User u = new User("max");↵ | |
4 | p.setName( "Steve" );↵ | 4 | ↵ | |
5 | p.setUserId( "steve" );↵ | |||
6 | s.persist( p );↵ | |||
7 | Group g = new Group();↵ | |||
8 | g.setName( "Admins" ); ↵ | 5 | u.getEmailAddresses().add( new Email("max@hibernate.org") );↵ | |
9 | g.getUsers().add( p );↵ | 6 | u.getEmailAddresses().add( ↵ | |
10 | s.persist( g );↵ | |||
11 | // force a flush and detachment here to test reattachment handling of the property-ref (HHH-1531) ↵ | 7 | new Email("max.andersen@jboss.com") );↵ | |
8 | s.persist(u);↵ | |||
12 | t.commit(); ↵ | 9 | t.commit();↵ | |
13 | s.close();↵ | 10 | s.close();↵ | |
14 | Person p2 = new Pers↵ | |||
11 | ↵ | |||
15 | on(); ↵ | 12 | s = openSession();↵ | |
16 | p2.setName( "Max" ); ↵ | 13 | t = s.beginTransaction();↵ | |
17 | p2.setUserId( "max" );↵ | 14 | ↵ | |
18 | g.getUsers().add( p2 );↵ | |||
19 | s = openSession();↵ | |||
20 | t = s.beginTransaction();↵ | |||
21 | s.update( g↵ | 15 | User u2 = (User) s.createCriteria(User.class).uniqueResult();↵ | |
16 | assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );↵ | |||
22 | ); ↵ | 17 | assertEquals( u2.getEmailAddresses().size(), 2 );↵ | |
23 | t.commit(); ↵ | 18 | t.commit();↵ | |
24 | s.close();↵ | 19 | s.close();↵ | |
25 | // test retrieval of the group ↵ | |||
26 | s = openSession(); ↵ | 20 | s = openSession();↵ | |
27 | t = s.beginTransaction(); ↵ | 21 | t = s.beginTransaction();↵ | |
28 | g = ( Group ) s.createQuery( "from Group g left join fetch g.users" ).uniqueResult();↵ | 22 | u2 = ( ↵ | |
29 | assertTrue( Hibernate.isInitialized( g.getUsers() ) );↵ | |||
30 | assertEquals( 2, g.getUsers().size() ↵ | 23 | User ) s.get( User.class, u.getUserName() );↵ | |
24 | u2.getEmailAddresses().size();↵ | |||
25 | assertEquals( 2, MyListType.lastInstantiationRequest );↵ | |||
31 | ); ↵ | 26 | t.commit();↵ | |
32 | s.delete( g ); ↵ | 27 | s.close();↵ | |
33 | s.createQuery( "delete Person" ).executeUpdate(↵ | 28 | s = openSession();↵ | |
29 | t = s.beginTransaction();↵ | |||
34 | ); ↵ | 30 | s.delete( u );↵ | |
35 | t.commit(); ↵ | 31 | t.commit();↵ | |
36 | s.close(); | 32 |
| |
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 | 321 |
Number of mapped statements | 20 |
Number of unmapped statements in the first code fragment | 10 |
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 | Person p = new Person(); |
| 3 | User u = new User("max"); | ||||||||||||||||||||||||
| 4 | u.getEmailAddresses().add(new Email("max@hibernate.org")); | ||||||||||||||||||||||||||
4 | p.setName("Steve"); | | ||||||||||||||||||||||||||
| 5 | u.getEmailAddresses().add(new Email("max.andersen@jboss.com")); | ||||||||||||||||||||||||||
5 | p.setUserId("steve"); | | ||||||||||||||||||||||||||
6 | s.persist(p); |
| 6 | s.persist(u); | ||||||||||||||||||||||||
7 | Group g = new Group(); | | ||||||||||||||||||||||||||
8 | g.setName("Admins"); | | ||||||||||||||||||||||||||
9 | g.getUsers().add(p); | | ||||||||||||||||||||||||||
10 | s.persist(g); |
| | |||||||||||||||||||||||||
11 | t.commit(); | 7 | t.commit(); | |||||||||||||||||||||||||
| 8 | s.close(); | ||||||||||||||||||||||||||
|
| 9 | s = openSession(); | |||||||||||||||||||||||||
|
| 10 | t = s.beginTransaction(); | |||||||||||||||||||||||||
12 | s.close(); | 15 | s.close(); | |||||||||||||||||||||||||
13 | Person p2 = new Person(); |
| 11 | User u2 = (User)s.createCriteria(User.class).uniqueResult(); | ||||||||||||||||||||||||
14 | p2.setName("Max"); |
| 13 | assertEquals(u2.getEmailAddresses().size(), 2); | ||||||||||||||||||||||||
15 | p2.setUserId("max"); |
| 20 | assertEquals(2, MyListType.lastInstantiationRequest); | ||||||||||||||||||||||||
16 | g.getUsers().add(p2); | | ||||||||||||||||||||||||||
17 | s = openSession(); | 16 | s = openSession(); | |||||||||||||||||||||||||
18 | t = s.beginTransaction(); | 17 | t = s.beginTransaction(); | |||||||||||||||||||||||||
19 | s.update(g); |
| | |||||||||||||||||||||||||
20 | t.commit(); | 14 | t.commit(); | |||||||||||||||||||||||||
21 | s.close(); | 22 | s.close(); | |||||||||||||||||||||||||
22 | s = openSession(); | 23 | s = openSession(); | |||||||||||||||||||||||||
23 | t = s.beginTransaction(); | 24 | t = s.beginTransaction(); | |||||||||||||||||||||||||
24 | g = (Group)s.createQuery("from Group g left join fetch g.users").uniqueResult(); |
| | |||||||||||||||||||||||||
25 | assertTrue(Hibernate.isInitialized(g.getUsers())); |
| 26 | t.commit(); | ||||||||||||||||||||||||
26 | assertEquals(2, g.getUsers().size()); |
| 12 | assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())); | ||||||||||||||||||||||||
|
| 18 | u2 = (User)s.get(User.class, u.getUserName()); | |||||||||||||||||||||||||
| 19 | u2.getEmailAddresses().size(); | ||||||||||||||||||||||||||
27 | s.delete(g); |
| 25 | s.delete(u); | ||||||||||||||||||||||||
28 | s.createQuery("delete Person").executeUpdate(); | | ||||||||||||||||||||||||||
29 | t.commit(); | 21 | t.commit(); | |||||||||||||||||||||||||
30 | s.close(); | 27 | s.close(); |
Row | Violation |
---|---|
1 | Expression p cannot be parameterized, because it has dependencies to/from statements that will be extracted |
2 | Expression u cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement s.persist(g); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | 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 |
6 | Expression p2.setName("Max") cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression assertEquals(u2.getEmailAddresses().size(),2) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression p2.setName("Max") is a void method call, and thus it cannot be parameterized |
9 | Expression assertEquals(u2.getEmailAddresses().size(),2) is a void method call, and thus it cannot be parameterized |
10 | Expression p2.setName("Max") cannot be parameterized, because it has dependencies to/from statements that will be extracted |
11 | Expression assertEquals(u2.getEmailAddresses().size(),2) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression p2.setName("Max") is a void method call, and thus it cannot be parameterized |
13 | Expression assertEquals(u2.getEmailAddresses().size(),2) is a void method call, and thus it cannot be parameterized |
14 | Expression p2.setUserId("max") cannot be parameterized, because it has dependencies to/from statements that will be extracted |
15 | Expression p2.setUserId("max") is a void method call, and thus it cannot be parameterized |
16 | Expression assertEquals(2,MyListType.lastInstantiationRequest) is a void method call, and thus it cannot be parameterized |
17 | Expression p2.setUserId("max") cannot be parameterized, because it has dependencies to/from statements that will be extracted |
18 | Expression p2.setUserId("max") is a void method call, and thus it cannot be parameterized |
19 | Expression assertEquals(2,MyListType.lastInstantiationRequest) is a void method call, and thus it cannot be parameterized |
20 | Unmatched statement s.update(g); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
21 | Unmatched statement g=(Group)s.createQuery("from Group g left join fetch g.users").uniqueResult(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
22 | Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
23 | Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized |
24 | Expression t.commit() is a void method call, and thus it cannot be parameterized |
25 | Expression t.commit() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
26 | Expression assertTrue(Hibernate.isInitialized(g.getUsers())) is a void method call, and thus it cannot be parameterized |
27 | Expression t.commit() is a void method call, and thus it cannot be parameterized |
28 | Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
29 | Expression assertEquals(2,g.getUsers().size()) is a void method call, and thus it cannot be parameterized |
30 | Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) is a void method call, and thus it cannot be parameterized |
31 | Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
32 | Expression assertEquals(2,g.getUsers().size()) is a void method call, and thus it cannot be parameterized |
33 | Expression assertTrue(Hibernate.isInitialized(u2.getEmailAddresses())) is a void method call, and thus it cannot be parameterized |
34 | Unmatched statement u2=(User)s.get(User.class,u.getUserName()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
35 | Expression u cannot be parameterized, because it has dependencies to/from statements that will be extracted |
36 | Type org.hibernate.test.propertyref.basic.Group of variable g does not match with type org.hibernate.test.usercollection.basic.User of variable u |
37 | Clone fragment #1 returns variables p, s, p2 , while Clone fragment #2 returns variables u, s, t, u2 |