package com.criteria.example;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestClient {
/**
* @param args
*/
public static void main(String[] args) {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Room.class);
config.configure(); // reads the *.cfg.xml file and understands the what is db and etc..
//new SchemaExport(config).create(true, true);
SessionFactory factory = config.buildSessionFactory();
Session session = factory.getCurrentSession();
/*session.beginTransaction();
Room r = new Room();
//ramesh.setEmpId(8634);
r.setName("RameS");
session.save(r);
session.getTransaction().commit();
*/
session.beginTransaction();
Query q = session.createQuery("from Room");
Iterator<Room> itr = (Iterator<Room>)q.iterate();
for(;itr.hasNext();){
System.out.println(itr.next().getName());
}
session.getTransaction().commit();
}
}