1 package org.hibernate.test.annotations.entity; 3 4 import org.hibernate.Session; 5 import org.hibernate.Transaction; 6 import org.hibernate.test.annotations.TestCase; 7 8 11 public class PropertyDefaultMappingsTest extends TestCase { 12 public PropertyDefaultMappingsTest(String x) { 13 super(x); 14 } 15 16 public void testSerializableObject() throws Exception { 17 Session s; 18 Transaction tx; 19 s = openSession(); 20 tx = s.beginTransaction(); 21 Country c = new Country(); 22 c.setName("France"); 23 Address a = new Address(); 24 a.setCity("Paris"); 25 a.setCountry(c); 26 s.persist(a); 27 tx.commit(); 28 s.close(); 29 30 s = openSession(); 31 tx = s.beginTransaction(); 32 Address reloadedAddress = (Address) s.get( Address.class, a.getId() ); 33 assertNotNull(reloadedAddress); 34 assertNotNull( reloadedAddress.getCountry() ); 35 assertEquals( a.getCountry().getName(), reloadedAddress.getCountry().getName() ); 36 tx.rollback(); 37 s.close(); 38 } 39 40 protected Class [] getMappings() { 41 return new Class [] { 42 Address.class 43 }; 44 } 45 } 46 | Popular Tags |