package hibernatedemo;
import hibernatedemo.person;
import java.util.*;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
publicclass Test {
publicstaticvoid main(String[] args)throwsException{
? ?Configuration cfg = new Configuration().addClass(person.class);
? ?SessionFactory sessions = cfg.buildSessionFactory();
? ?new SchemaExport(cfg).create(true, true);
? ?Session s = sessions.openSession();
? ?Query q = s.createQuery("from person");
? ?for(Iterator it = q.iterate();it.hasNext();){
? ? ?person b = (person)it.next();
? ? ?System.out.println("##name:"+b.getName());
? ?}
}
}
引自:http://www.aygfsteel.com/TrampEagle/articles/29972.html
import hibernatedemo.person;
import java.util.*;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
publicclass Test {
publicstaticvoid main(String[] args)throwsException{
? ?Configuration cfg = new Configuration().addClass(person.class);
? ?SessionFactory sessions = cfg.buildSessionFactory();
? ?new SchemaExport(cfg).create(true, true);
? ?Session s = sessions.openSession();
? ?Query q = s.createQuery("from person");
? ?for(Iterator it = q.iterate();it.hasNext();){
? ? ?person b = (person)it.next();
? ? ?System.out.println("##name:"+b.getName());
? ?}
}
}
引自:http://www.aygfsteel.com/TrampEagle/articles/29972.html