KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > fetch > FetchingTest


1 //$Id: FetchingTest.java,v 1.1 2005/07/20 00:18:05 epbernard Exp $
2
package org.hibernate.test.annotations.fetch;
3
4 import java.util.Date JavaDoc;
5
6 import org.hibernate.test.annotations.TestCase;
7 import org.hibernate.Session;
8 import org.hibernate.Transaction;
9 import org.hibernate.Hibernate;
10
11 /**
12  * @author Emmanuel Bernard
13  */

14 public class FetchingTest extends TestCase {
15     public void testLazy() throws Exception JavaDoc {
16         Session s;
17         Transaction tx;
18         s = openSession();
19         tx = s.beginTransaction();
20         Person p = new Person( "Gavin", "King", "JBoss Inc" );
21         Stay stay = new Stay(p, new Date JavaDoc(), new Date JavaDoc(), "A380", "Blah", "Blah");
22         p.addStay( stay );
23         s.persist( p );
24         tx.commit();
25         s.clear();
26         tx = s.beginTransaction();
27         p = (Person) s.createQuery( "from Person p where p.firstName = :name")
28                 .setParameter( "name", "Gavin").uniqueResult();
29         assertFalse( Hibernate.isInitialized( p.getStays() ) );
30         s.delete( p );
31         tx.commit();
32         s.close();
33     }
34
35     public FetchingTest(String JavaDoc x) {
36         super( x );
37     }
38
39     protected Class JavaDoc[] getMappings() {
40         return new Class JavaDoc[] {
41             Person.class,
42             Stay.class
43         };
44     }
45 }
46
Popular Tags