1 package org.hibernate.test.annotations.fetch; 3 4 import java.util.Date ; 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 14 public class FetchingTest extends TestCase { 15 public void testLazy() throws Exception { 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 (), new Date (), "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 x) { 36 super( x ); 37 } 38 39 protected Class [] getMappings() { 40 return new Class [] { 41 Person.class, 42 Stay.class 43 }; 44 } 45 } 46 | Popular Tags |