KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > compositeelement > CompositeElementTest


1 //$Id: CompositeElementTest.java,v 1.1 2004/09/02 02:30:28 oneovthafew Exp $
2
package org.hibernate.test.compositeelement;
3
4 import junit.framework.Test;
5 import junit.framework.TestSuite;
6
7 import org.hibernate.Session;
8 import org.hibernate.Transaction;
9 import org.hibernate.test.TestCase;
10
11 /**
12  * @author Gavin King
13  */

14 public class CompositeElementTest extends TestCase {
15     
16     public CompositeElementTest(String JavaDoc str) {
17         super(str);
18     }
19     
20     public void testHandSQL() {
21         Session s = openSession();
22         Transaction t = s.beginTransaction();
23         Child c = new Child("Child One");
24         Parent p = new Parent("Parent");
25         p.getChildren().add(c);
26         c.setParent(p);
27         s.save(p);
28         s.flush();
29         
30         p.getChildren().remove(c);
31         c.setParent(null);
32         s.flush();
33         
34         p.getChildren().add(c);
35         c.setParent(p);
36         t.commit();
37         s.close();
38         
39         s = openSession();
40         t = s.beginTransaction();
41         s.createQuery("select distinct p from Parent p join p.children c where c.name like 'Child%'").uniqueResult();
42         s.clear();
43         s.createQuery("select new Child(c.name) from Parent p left outer join p.children c where c.name like 'Child%'").uniqueResult();
44         s.clear();
45         //s.createQuery("select c from Parent p left outer join p.children c where c.name like 'Child%'").uniqueResult(); //we really need to be able to do this!
46
s.clear();
47         p = (Parent) s.createQuery("from Parent p left join fetch p.children").uniqueResult();
48         t.commit();
49         s.close();
50     }
51
52     
53     protected String JavaDoc[] getMappings() {
54         return new String JavaDoc[] { "compositeelement/Parent.hbm.xml" };
55     }
56
57     public static Test suite() {
58         return new TestSuite(CompositeElementTest.class);
59     }
60
61 }
62
63
Popular Tags