// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.type.Type;

public class HibTest {
    private static void selectone() {
        SessionFactory sf = new Configuration().configure("/hibernateconfig.xml").buildSessionFactory();
        Session s = sf.openSession();
        T1 r = (T1)s.load(T1.class, new Integer(2));
        System.out.println(r.getF1() + " " + r.getF2());
        s.close();
    }
    private static void selectall() {
        SessionFactory sf = new Configuration().configure("/hibernateconfig.xml").buildSessionFactory();
        Session s = sf.openSession();
        List<T1> all = s.createQuery("FROM T1 AS t1").list();
        for(int i = 0; i < all.size(); i++) {
            T1 r = all.get(i);
            System.out.println(r.getF1() + " " + r.getF2());
        }
        s.close();
    }
    private static void selectsome() {
        SessionFactory sf = new Configuration().configure("/hibernateconfig.xml").buildSessionFactory();
        Session s = sf.openSession();
        Query q = s.createQuery("FROM T1 AS t1 WHERE F2 NOT LIKE :f2");
        q.setParameter("f2", "B%", Hibernate.STRING);
        List<T1> all = q.list();
        for(int i = 0; i < all.size(); i++) {
            T1 r = all.get(i);
            System.out.println(r.getF1() + " " + r.getF2());
        }
        s.close();
    }
    public static void main(String[] args) {
        selectone();
        selectall();
        selectsome();
    }
}
