Search in sources :

Example 1 with Single

use of org.hibernate.test.legacy.Single in project hibernate-orm by hibernate.

the class SQLFunctionsInterSystemsTest method testSetProperties.

public void testSetProperties() throws Exception {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Simple simple = new Simple(Long.valueOf(10));
    simple.setName("Simple 1");
    s.save(simple);
    Query q = s.createQuery("from Simple s where s.name=:name and s.count=:count");
    q.setProperties(simple);
    assertTrue(q.list().get(0) == simple);
    //misuse of "Single" as a propertyobject, but it was the first testclass i found with a collection ;)
    Single single = new // trivial hack to test properties with arrays.
    Single() {

        @SuppressWarnings({ "unchecked" })
        String[] getStuff() {
            return (String[]) getSeveral().toArray(new String[getSeveral().size()]);
        }
    };
    List l = new ArrayList();
    l.add("Simple 1");
    l.add("Slimeball");
    single.setSeveral(l);
    q = s.createQuery("from Simple s where s.name in (:several)");
    q.setProperties(single);
    assertTrue(q.list().get(0) == simple);
    q = s.createQuery("from Simple s where s.name in (:stuff)");
    q.setProperties(single);
    assertTrue(q.list().get(0) == simple);
    s.delete(simple);
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) Single(org.hibernate.test.legacy.Single) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) Simple(org.hibernate.test.legacy.Simple)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Query (org.hibernate.Query)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 Simple (org.hibernate.test.legacy.Simple)1 Single (org.hibernate.test.legacy.Single)1