/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package esimene; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Restrictions; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import org.hibernate.criterion.Order; /** * * @author Opetaja */ public class Test3a { @SuppressWarnings("unchecked") public static void main(String[] arg){ Logger.getLogger("org.hibernate").setLevel(Level.WARNING); Configuration c = new Configuration().configure(); SessionFactory sf = c.buildSessionFactory(); Session s = sf.openSession(); try { Criteria cr=s.createCriteria(Isik.class); cr.add(Restrictions.eq("perekonnanimi", "Tamm")). add(Restrictions.gt("id", 0)). addOrder(Order.asc("eesnimi")); List vastus=(List)cr.list(); for(Isik isik: vastus){ System.out.println(isik.getEesnimi()); } Isik eemaldatav=(Isik)s.get(Isik.class, 0); if(eemaldatav!=null){ Transaction tx=s.beginTransaction(); s.delete(eemaldatav); tx.commit(); } } catch (Exception e) { System.out.println(e.getMessage().toString()); } s.close(); } }