1 | public void testBatchOrdering() {
| | 1 | public void testIterateWithEvictBottomOfLoop() {
|
2 | Session s = openSession();
| | 2 | Session s = openSession();
|
3 | s.beginTransaction();
| | 3 | s.beginTransaction();
|
4 | int iterations = 12;
| | 4 | Set parents = new HashSet();
|
5 | for ( int i = 0; i < iterations; i++ ) {
| | 5 | for (int i=0; i<5; i++) {
|
6 | User user = new User( "user-" + i );
| | 6 | Parent p = new Parent( String.valueOf( i + 100 ) );
|
7 | Group group = new Group( "group-" + i );
| | 7 | Child child = new Child( "child" + i );
|
8 | s.save( user );
| | 8 | child.setParent( p );
|
9 | s.save( group );
| | 9 | p.getChildren().add( child );
|
10 | user.addMembership( group );
| | 10 | s.save( p );
|
11 | }
| | 11 | parents.add(p);
|
12 | StatsBatcher.reset();
| | 12 | }
|
13 | s.getTransaction().commit();
| | 13 | s.getTransaction().commit();
|
14 | s.close();
| | 14 | s.close();
|
15 |
| | 15 |
|
16 | assertEquals( 6, StatsBatcher.batchSizes.size() ); // 2 batches of each insert statement
| | 16 | s = openSession();
|
17 |
| | 17 | s.beginTransaction();
|
18 | s = openSession();
| | 18 | for (Iterator it = s.createQuery( "from Parent" ).iterate(); it.hasNext(); ) {
|
19 | s.beginTransaction();
| | 19 | Parent p = (Parent) it.next();
|
20 | Iterator users = s.createQuery( "from User u left join fetch u.memberships m left join fetch m.group" ).list().iterator();
| | 20 | assertEquals( 1, p.getChildren().size() );
|
21 | while ( users.hasNext() ) {
| | 21 | s.evict(p);
|
22 | s.delete( users.next() );
| | 22 | }
|
23 | }
| | 23 | s.getTransaction().commit();
|
24 | s.getTransaction().commit();
| | 24 | s.close();
|
25 | s.close();
| | 25 |
|
26 | } | | 26 | s = openSession();
|
| | | 27 | s.beginTransaction();
|
| | | 28 | for (Iterator it=parents.iterator(); it.hasNext(); ) {
|
| | | 29 | s.delete(it.next());
|
| | | 30 | }
|
| | | 31 | s.getTransaction().commit();
|
| | | 32 | s.close();
|
| | | 33 | } |