Java基础代码库:Hibernate保存数据的基本流程

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.hibernate.pojo.Student;

public class StudentTest
{
    public static void main(String[] args)
    {
        Student s = new Student();
        s.setAge(18);
        s.setName("song");
        
        Configuration cfg = new Configuration();
        SessionFactory sf = cfg.configure().buildSessionFactory();
        Session session = sf.openSession();
        session.beginTransaction();
        session.save(s);
        session.getTransaction().commit();
        session.close();
        sf.close();    
    }
}
posted @ 2012-08-13 20:53  苏堤白堤杨公堤  阅读(580)  评论(0编辑  收藏  举报