KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > array > ArrayTest


1 //$Id: ArrayTest.java,v 1.1 2005/05/12 13:33:26 epbernard Exp $
2
package org.hibernate.test.annotations.array;
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 ArrayTest extends TestCase {
12
13     public void testOneToMany() throws Exception JavaDoc {
14         Session s;
15         Transaction tx;
16         s = openSession();
17         tx = s.beginTransaction();
18         Competitor c1 = new Competitor();
19         c1.setName( "Renault" );
20         Competitor c2 = new Competitor();
21         c2.setName( "Ferrari" );
22         Contest contest = new Contest();
23         contest.setResults( new Competitor[] {c1, c2} );
24         s.persist( contest );
25         tx.commit();
26         s.close();
27
28         s = openSession();
29         tx = s.beginTransaction();
30         contest = (Contest) s.get( Contest.class, contest.getId() );
31         assertNotNull( contest );
32         assertNotNull( contest.getResults() );
33         assertEquals( 2, contest.getResults().length );
34         assertEquals( c2.getName(), contest.getResults()[1].getName() );
35         tx.commit();
36         s.close();
37     }
38
39     public ArrayTest(String JavaDoc x) {
40         super( x );
41     }
42
43     protected Class JavaDoc[] getMappings() {
44         return new Class JavaDoc[] {
45             Competitor.class,
46             Contest.class
47         };
48     }
49 }
50
Popular Tags