Search in sources :

Example 46 with Serializable

use of java.io.Serializable in project hibernate-orm by hibernate.

the class FooBarTest method testSerializableType.

@Test
public void testSerializableType() throws Exception {
    Session s = openSession();
    s.beginTransaction();
    Vetoer v = new Vetoer();
    v.setStrings(new String[] { "foo", "bar", "baz" });
    s.save(v);
    Serializable id = s.save(v);
    v.getStrings()[1] = "osama";
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    v = (Vetoer) s.load(Vetoer.class, id);
    assertTrue("serializable type", v.getStrings()[1].equals("osama"));
    s.delete(v);
    s.delete(v);
    s.flush();
    s.getTransaction().commit();
    s.close();
}
Also used : Serializable(java.io.Serializable) Session(org.hibernate.Session) Test(org.junit.Test)

Example 47 with Serializable

use of java.io.Serializable in project hibernate-orm by hibernate.

the class ParentChildTest method testQueryOneToOne.

@Test
public void testQueryOneToOne() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Serializable id = s.save(new Parent());
    assertTrue(s.createQuery("from Parent p left join fetch p.child").list().size() == 1);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Parent p = (Parent) s.createQuery("from Parent p left join fetch p.child").uniqueResult();
    assertTrue(p.getChild() == null);
    s.createQuery("from Parent p join p.child c where c.x > 0").list();
    s.createQuery("from Child c join c.parent p where p.x > 0").list();
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    s.delete(s.get(Parent.class, id));
    t.commit();
    s.close();
}
Also used : Serializable(java.io.Serializable) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 48 with Serializable

use of java.io.Serializable in project hibernate-orm by hibernate.

the class MasterDetailTest method testInterface.

@Test
public void testInterface() throws Exception {
    Session s = openSession();
    s.beginTransaction();
    Serializable id = s.save(new BasicNameable());
    s.getTransaction().commit();
    s.close();
    s = openSession();
    s.beginTransaction();
    Nameable n = (Nameable) s.load(Nameable.class, id);
    s.delete(n);
    s.getTransaction().commit();
    s.close();
}
Also used : Serializable(java.io.Serializable) Session(org.hibernate.Session) Test(org.junit.Test)

Example 49 with Serializable

use of java.io.Serializable in project hibernate-orm by hibernate.

the class MultiTableTest method testMultiTable.

@Test
public void testMultiTable() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Multi multi = new Multi();
    multi.setExtraProp("extra");
    multi.setName("name");
    Top simp = new Top();
    simp.setDate(new Date());
    simp.setName("simp");
    Serializable mid = s.save(multi);
    Serializable sid = s.save(simp);
    SubMulti sm = new SubMulti();
    sm.setAmount(66.5f);
    Serializable smid = s.save(sm);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    multi.setExtraProp(multi.getExtraProp() + "2");
    //multi.setCount( multi.getCount() + 1 );
    multi.setName("new name");
    s.update(multi);
    simp.setName("new name");
    s.update(simp);
    sm.setAmount(456.7f);
    s.update(sm);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    multi = (Multi) s.load(Multi.class, mid);
    assertTrue(multi.getExtraProp().equals("extra2"));
    multi.setExtraProp(multi.getExtraProp() + "3");
    //multi.setCount( multi.getCount() + 1 );
    assertTrue(multi.getName().equals("new name"));
    multi.setName("newer name");
    sm = (SubMulti) s.load(SubMulti.class, smid);
    assertTrue(sm.getAmount() == 456.7f);
    sm.setAmount(23423f);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    multi = (Multi) s.load(Top.class, mid);
    simp = (Top) s.load(Top.class, sid);
    assertTrue(!(simp instanceof Multi));
    assertTrue(multi.getExtraProp().equals("extra23"));
    //multi.setCount( multi.getCount() + 1 );
    assertTrue(multi.getName().equals("newer name"));
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Iterator iter = s.createQuery("select\n\nt from Top t where t.count>0").iterate();
    boolean foundSimp = false;
    boolean foundMulti = false;
    boolean foundSubMulti = false;
    while (iter.hasNext()) {
        Object o = iter.next();
        if ((o instanceof Top) && !(o instanceof Multi))
            foundSimp = true;
        if (o instanceof Multi && !(o instanceof SubMulti))
            foundMulti = true;
        if (o instanceof SubMulti)
            foundSubMulti = true;
    }
    assertTrue(foundSimp && foundMulti && foundSubMulti);
    s.createQuery("from Multi m where m.count>0 and m.extraProp is not null").list();
    s.createQuery("from Top m where m.count>0 and m.name is not null").list();
    s.createQuery("from Lower m where m.other is not null").list();
    s.createQuery("from Multi m where m.other.id = 1").list();
    s.createQuery("from SubMulti m where m.amount > 0.0").list();
    assertTrue(s.createQuery("from Multi").list().size() == 2);
    assertTrue(s.createQuery("from Multi m where m.class = SubMulti").list().size() == 1);
    assertTrue(s.createQuery("from Top m where m.class = Multi").list().size() == 1);
    assertTrue(s.createQuery("from Top").list().size() == 3);
    assertTrue(s.createQuery("from Lower").list().size() == 0);
    assertTrue(s.createQuery("from SubMulti").list().size() == 1);
    s.createQuery("from Lower ls join ls.bag s where s.id is not null").list();
    s.createQuery("from Lower ls join ls.set s where s.id is not null").list();
    if (!(getDialect() instanceof MySQLDialect))
        s.createQuery("from SubMulti sm where exists elements(sm.children)").list();
    List l = s.createCriteria(Top.class).list();
    assertTrue(l.size() == 3);
    assertTrue(s.createCriteria(SubMulti.class).list().size() == 1);
    assertTrue(s.createCriteria(SubMulti.class).add(Restrictions.lt("amount", new Float(0))).list().size() == 0);
    assertTrue(s.createCriteria(SubMulti.class).add(Restrictions.ge("amount", new Float(0))).list().size() == 1);
    t.commit();
    s.close();
    // if there are more than one tables/views/subqueries in the FROM clause
    if (!(getDialect() instanceof AbstractHANADialect)) {
        s = openSession();
        t = s.beginTransaction();
        multi = (Multi) s.load(Top.class, mid, LockMode.UPGRADE);
        simp = (Top) s.load(Top.class, sid);
        s.lock(simp, LockMode.UPGRADE_NOWAIT);
        t.commit();
        s.close();
    }
    s = openSession();
    t = s.beginTransaction();
    s.update(multi);
    s.delete(multi);
    assertEquals(2, doDelete(s, "from Top"));
    t.commit();
    s.close();
}
Also used : Serializable(java.io.Serializable) Date(java.util.Date) AbstractHANADialect(org.hibernate.dialect.AbstractHANADialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) Transaction(org.hibernate.Transaction) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test)

Example 50 with Serializable

use of java.io.Serializable in project hibernate-orm by hibernate.

the class MultiTableTest method testMultiTableGeneratedId.

@Test
public void testMultiTableGeneratedId() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Multi multi = new Multi();
    multi.setExtraProp("extra");
    //multi.setCount(666);
    multi.setName("name");
    Top simp = new Top();
    simp.setDate(new Date());
    simp.setName("simp");
    //simp.setCount(132);
    Serializable multiId = s.save(multi);
    Serializable simpId = s.save(simp);
    SubMulti sm = new SubMulti();
    sm.setAmount(66.5f);
    Serializable smId = s.save(sm);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    multi.setExtraProp(multi.getExtraProp() + "2");
    //multi.setCount( multi.getCount() + 1 );
    multi.setName("new name");
    s.update(multi);
    simp.setName("new name");
    s.update(simp);
    sm.setAmount(456.7f);
    s.update(sm);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    multi = (Multi) s.load(Multi.class, multiId);
    assertTrue(multi.getExtraProp().equals("extra2"));
    multi.setExtraProp(multi.getExtraProp() + "3");
    //multi.setCount( multi.getCount() + 1 );
    assertTrue(multi.getName().equals("new name"));
    multi.setName("newer name");
    sm = (SubMulti) s.load(SubMulti.class, smId);
    assertTrue(sm.getAmount() == 456.7f);
    sm.setAmount(23423f);
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    multi = (Multi) s.load(Top.class, multiId);
    simp = (Top) s.load(Top.class, simpId);
    assertTrue(!(simp instanceof Multi));
    assertTrue(multi.getExtraProp().equals("extra23"));
    //multi.setCount( multi.getCount() + 1 );
    assertTrue(multi.getName().equals("newer name"));
    t.commit();
    s.close();
    s = openSession();
    t = s.beginTransaction();
    Iterator iter = s.createQuery("select\n\nt from Top t where t.count>0").iterate();
    boolean foundSimp = false;
    boolean foundMulti = false;
    boolean foundSubMulti = false;
    while (iter.hasNext()) {
        Object o = iter.next();
        if ((o instanceof Top) && !(o instanceof Multi))
            foundSimp = true;
        if (o instanceof Multi && !(o instanceof SubMulti))
            foundMulti = true;
        if (o instanceof SubMulti)
            foundSubMulti = true;
    }
    assertTrue(foundSimp && foundMulti && foundSubMulti);
    s.createQuery("from Multi m where m.count>0 and m.extraProp is not null").list();
    s.createQuery("from Top m where m.count>0 and m.name is not null").list();
    s.createQuery("from Lower m where m.other is not null").list();
    s.createQuery("from Multi m where m.other.id = 1").list();
    s.createQuery("from SubMulti m where m.amount > 0.0").list();
    assertTrue(s.createQuery("from Multi").list().size() == 2);
    /*assertTrue(
			s.find("from m in class Multi where m.class = Multi").size()==1
		);*/
    assertTrue(s.createQuery("from Top").list().size() == 3);
    assertTrue(s.createQuery("from Lower").list().size() == 0);
    assertTrue(s.createQuery("from SubMulti").list().size() == 1);
    s.createQuery("from Lower ls join ls.bag s where s.id is not null").list();
    if (!(getDialect() instanceof MySQLDialect))
        s.createQuery("from SubMulti sm where exists elements(sm.children)").list();
    t.commit();
    s.close();
    // if there are more than one tables/views/subqueries in the FROM clause
    if (!(getDialect() instanceof AbstractHANADialect)) {
        s = openSession();
        t = s.beginTransaction();
        multi = (Multi) s.load(Top.class, multiId, LockMode.UPGRADE);
        simp = (Top) s.load(Top.class, simpId);
        s.lock(simp, LockMode.UPGRADE_NOWAIT);
        t.commit();
        s.close();
    }
    s = openSession();
    t = s.beginTransaction();
    s.update(multi);
    s.delete(multi);
    assertEquals(2, doDelete(s, "from Top"));
    t.commit();
    s.close();
}
Also used : AbstractHANADialect(org.hibernate.dialect.AbstractHANADialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) Serializable(java.io.Serializable) Transaction(org.hibernate.Transaction) Iterator(java.util.Iterator) Date(java.util.Date) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Serializable (java.io.Serializable)1280 Test (org.junit.Test)334 HashMap (java.util.HashMap)265 ArrayList (java.util.ArrayList)215 Map (java.util.Map)127 List (java.util.List)94 Metacard (ddf.catalog.data.Metacard)89 IOException (java.io.IOException)89 HashSet (java.util.HashSet)70 Session (org.hibernate.Session)63 Task (org.apache.hadoop.hive.ql.exec.Task)57 ByteArrayInputStream (java.io.ByteArrayInputStream)50 Set (java.util.Set)50 ObjectInputStream (java.io.ObjectInputStream)43 Date (java.util.Date)41 LinkedHashMap (java.util.LinkedHashMap)40 EntityPersister (org.hibernate.persister.entity.EntityPersister)34 File (java.io.File)33 Iterator (java.util.Iterator)33 URI (java.net.URI)32