Posted on 2006-07-28 17:02
lubaolin 阅读(380)
评论(0) 编辑 收藏
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.blogjava.net/TrampEagle/articles/29972.html