FileDocCategorySizeDatePackage
InsertOrderingTest.javaAPI DocHibernate 3.2.54047Wed Apr 11 09:25:14 BST 2007org.hibernate.test.insertordering

InsertOrderingTest

public class InsertOrderingTest extends org.hibernate.junit.functional.FunctionalTestCase
{@inheritDoc}
author
Steve Ebersole

Fields Summary
Constructors Summary
public InsertOrderingTest(String string)

		super( string );
	
Methods Summary
public voidconfigure(org.hibernate.cfg.Configuration cfg)

		super.configure( cfg );
		cfg.setProperty( Environment.ORDER_INSERTS, "true" );
		cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "10" );
		cfg.setProperty( Environment.BATCH_STRATEGY, StatsBatcherFactory.class.getName() );
	
public java.lang.String[]getMappings()

		return new String[] { "insertordering/Mapping.hbm.xml" };
	
public static junit.framework.Testsuite()

		return new FunctionalTestClassTestSuite( InsertOrderingTest.class );
	
public voidtestBatchOrdering()

		Session s = openSession();
		s.beginTransaction();
		int iterations = 12;
		for ( int i = 0; i < iterations; i++ ) {
			User user = new User( "user-" + i );
			Group group = new Group( "group-" + i );
			s.save( user );
			s.save( group );
			user.addMembership( group );
		}
		StatsBatcher.reset();
		s.getTransaction().commit();
		s.close();

		assertEquals( 6, StatsBatcher.batchSizes.size() );  // 2 batches of each insert statement

		s = openSession();
		s.beginTransaction();
		Iterator users = s.createQuery( "from User u left join fetch u.memberships m left join fetch m.group" ).list().iterator();
		while ( users.hasNext() ) {
			s.delete( users.next() );
		}
		s.getTransaction().commit();
		s.close();