FileDocCategorySizeDatePackage
KeyManyToOneTest.javaAPI DocHibernate 3.2.52165Tue Jan 23 05:54:42 GMT 2007org.hibernate.test.keymanytoone.bidir.embedded

KeyManyToOneTest

public class KeyManyToOneTest extends org.hibernate.test.TestCase
author
Steve Ebersole

Fields Summary
Constructors Summary
public KeyManyToOneTest(String name)

		super( name );
	
Methods Summary
protected voidconfigure(org.hibernate.cfg.Configuration cfg)

		super.configure( cfg );
		cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
	
protected java.lang.String[]getMappings()

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

		return new FunctionalTestClassTestSuite( KeyManyToOneTest.class );
	
public voidtestLoadingStrategies()

		Session s = openSession();
		s.beginTransaction();
		Customer cust = new Customer( "Acme, Inc." );
		Order order = new Order( cust, 1 );
		cust.getOrders().add( order );
		s.save( cust );
		s.getTransaction().commit();
		s.close();

		s = openSession();
		s.beginTransaction();

		cust = ( Customer ) s.get( Customer.class, cust.getId() );
		assertEquals( 1, cust.getOrders().size() );
		s.clear();

		cust = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();
		assertEquals( 1, cust.getOrders().size() );
		s.clear();

		cust = ( Customer ) s.createQuery( "from Customer c join fetch c.orders" ).uniqueResult();
		assertEquals( 1, cust.getOrders().size() );
		s.clear();

		s.delete( cust );
		s.getTransaction().commit();
		s.close();
	
public voidtestSaveCascadedToKeyManyToOne()

		// test cascading a save to an association with a key-many-to-one which refers to a
		// just saved entity
		Session s = openSession();
		s.beginTransaction();
		Customer cust = new Customer( "Acme, Inc." );
		Order order = new Order( cust, 1 );
		cust.getOrders().add( order );
		s.save( cust );
		s.flush();
		assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
		s.delete( cust );
		s.getTransaction().commit();
		s.close();