继续关注我的C语言学习博客

林临的地盘

java学习博客
posts - 44, comments - 28, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

用hibernate建表 续

Posted on 2006-07-28 17:02 lubaolin 阅读(374) 评论(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

只有注册用户登录后才能发表评论。


网站导航:
 
继续关注我的C语言学习博客