~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/keymanytoone/bidir/component/LazyKeyManyToOneTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hibernate.test.keymanytoone.bidir.component;
 
2
 
 
3
import junit.framework.Test;
 
4
 
 
5
import org.hibernate.test.TestCase;
 
6
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
7
import org.hibernate.cfg.Configuration;
 
8
import org.hibernate.cfg.Environment;
 
9
import org.hibernate.Session;
 
10
 
 
11
/**
 
12
 * @author Steve Ebersole
 
13
 */
 
14
public class LazyKeyManyToOneTest extends TestCase {
 
15
        public LazyKeyManyToOneTest(String name) {
 
16
                super( name );
 
17
        }
 
18
 
 
19
        protected String[] getMappings() {
 
20
                return new String[] { "keymanytoone/bidir/component/LazyMapping.hbm.xml" };
 
21
        }
 
22
 
 
23
        public static Test suite() {
 
24
                return new FunctionalTestClassTestSuite( LazyKeyManyToOneTest.class );
 
25
        }
 
26
 
 
27
        protected void configure(Configuration cfg) {
 
28
                super.configure( cfg );
 
29
                cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
 
30
        }
 
31
 
 
32
        public void testSaveCascadedToKeyManyToOne() {
 
33
                // test cascading a save to an association with a key-many-to-one which refers to a
 
34
                // just saved entity
 
35
                Session s = openSession();
 
36
                s.beginTransaction();
 
37
                Customer cust = new Customer( "Acme, Inc." );
 
38
                Order order = new Order( new Order.Id( cust, 1 ) );
 
39
                cust.getOrders().add( order );
 
40
                s.save( cust );
 
41
                s.flush();
 
42
                assertEquals( 2, sfi().getStatistics().getEntityInsertCount() );
 
43
                s.delete( cust );
 
44
                s.getTransaction().commit();
 
45
                s.close();
 
46
        }
 
47
 
 
48
        public void testLoadingStrategies() {
 
49
                Session s = openSession();
 
50
                s.beginTransaction();
 
51
                Customer cust = new Customer( "Acme, Inc." );
 
52
                Order order = new Order( new Order.Id( cust, 1 ) );
 
53
                cust.getOrders().add( order );
 
54
                s.save( cust );
 
55
                s.getTransaction().commit();
 
56
                s.close();
 
57
 
 
58
                s = openSession();
 
59
                s.beginTransaction();
 
60
 
 
61
                cust = ( Customer ) s.get( Customer.class, cust.getId() );
 
62
                assertEquals( 1, cust.getOrders().size() );
 
63
                s.clear();
 
64
 
 
65
                cust = ( Customer ) s.createQuery( "from Customer" ).uniqueResult();
 
66
                assertEquals( 1, cust.getOrders().size() );
 
67
                s.clear();
 
68
 
 
69
                cust = ( Customer ) s.createQuery( "from Customer c join fetch c.orders" ).uniqueResult();
 
70
                assertEquals( 1, cust.getOrders().size() );
 
71
                s.clear();
 
72
 
 
73
                s.delete( cust );
 
74
                s.getTransaction().commit();
 
75
                s.close();
 
76
        }
 
77
}