KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > entity > PropertyDefaultMappingsTest


1 //$Id: PropertyDefaultMappingsTest.java,v 1.1 2005/05/12 13:33:32 epbernard Exp $
2
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 /**
9  * @author Emmanuel Bernard
10  */

11 public class PropertyDefaultMappingsTest extends TestCase {
12     public PropertyDefaultMappingsTest(String JavaDoc x) {
13         super(x);
14     }
15
16     public void testSerializableObject() throws Exception JavaDoc {
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 JavaDoc[] getMappings() {
41         return new Class JavaDoc[] {
42             Address.class
43         };
44     }
45 }
46
Popular Tags