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();
}