import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class test1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Student s = new Students; s.setId(1); s.setName(2); S.setAge; Configuration configuration = new Configuration(); SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = sessionFactory.openSession(); //用事务方式储存\ session.beginTransaction(); session.save(s); session.getTransaction().commit(); session.close(); //sessionFactory也要关闭 sessionFactory.close(); } }
STUDENT的实体类和XML文件在这里就不贴出来了。有兴趣的可以自己建一个表,然后映射一下。看到SET以后,知道这表里有哪三个字段了吧。