01: package org.makumba.db.hibernate;
02:
03: import java.util.List;
04: import java.util.Vector;
05:
06: import org.hibernate.Query;
07: import org.hibernate.Session;
08: import org.hibernate.SessionFactory;
09: import org.hibernate.Transaction;
10: import org.makumba.HibernateSFManager;
11:
12: public class HibernateTest {
13:
14: public static void main(String[] args) {
15:
16: Vector dds = new Vector();
17: dds.addElement("general.Person");
18:
19: //Vector dds= org.makumba.MakumbaSystem.mddsInDirectory("dataDefinitions");
20: //SessionFactory sf = HibernateSFManager.getSF(dds, "dataDefinitions", "org/makumba/db/hibernate/localhost_mysql_karambasmall.cfg.xml");
21: SessionFactory sf = HibernateSFManager.getSF();
22: Session session = sf.openSession();
23: Transaction tx = session.beginTransaction();
24:
25: // List languages = new ArrayList();
26: // languages.add(new Language("English", "en"));
27: // languages.add(new Language("French", "fr"));
28: //
29: // Person brother = new Person();
30: // brother.setWeight(new Double("50"));
31: //
32: // Individual indiv = new Individual();
33: // indiv.setName("Bart");
34: // indiv.setSurname("Van de Velde");
35: //
36: // Address address = new Address("fzpoegjfzpojgpz");
37: //
38: // Person person = new Person();
39: // person.setWeight(new Double("73.6"));
40: // person.setBrother(brother);
41: // person.setIndiv(indiv);
42: // person.setBirthdate(new Date());
43: // person.setHobbies(new Text("Hobybybybybybyybybybybybyby."));
44: // person.setSpeaks(languages);
45: // person.addAddress(address);
46: // person.addCharSet(new CharSet("a"));
47: // person.addCharSet(new CharSet("b"));
48: // person.addIntSet(new IntSet(new Integer(0)));
49: // person.addIntSet(new IntSet(new Integer(1)));
50:
51: // session.saveOrUpdate(person);
52: // tx.commit();
53: //
54: //Query q = session.createQuery("UPDATE test.Person SET indiv.name = :newName WHERE indiv.name = :oldName").setString("newName", "Johannes").setString("oldName", "Bart");
55:
56: // SELECT p would select the whole test.Person!
57: //Query q = session.createQuery("SELECT p.id FROM test.Person p");
58:
59: // FROM test.Person p, p.indiv i does not pass the HQL-SQL parser
60: //Query q = session.createQuery("SELECT i.surname, p.weight FROM test.Person p, IN(p.indiv) i WHERE i.name = 'Bart'");
61:
62: // FROM test.Person p, p.intSet s, p.speaks l does not pass the HQL-SQL parser
63: // SELECT s will select the whole enumerator rather than just the value!
64: //Query q = session.createQuery("SELECT s.enum, s1.name FROM test.Person p JOIN p.intSet s JOIN p.speaks s1 WHERE p.indiv.name = 'Bart'");
65:
66: // FROM test.Person p, p.address a does not pass the HQL-SQL parser
67: //Query q = session.createQuery("SELECT a.streetno FROM test.Person p JOIN p.address a WHERE p.indiv.name = 'Bart'");
68:
69: // a manual pointer join
70: //Query q = session.createQuery("SELECT i.name, p.weight FROM test.Person p, test.Individual i WHERE p.indiv = i");
71:
72: // a more automatic pointer join
73: Query q = session
74: .createQuery("SELECT p.name, p.surname FROM general.Person p WHERE p.surname='Mayer'");
75:
76: List list = q.list();
77: for (int i = 0; i < list.size(); i++) {
78: if (list.get(i) == null)
79: continue;
80: //test = (Person)list.get(i);
81: System.out.println(list.get(i).getClass());
82: System.out.println(list.get(i));
83:
84: }
85: session.close();
86: }
87: }
|