模版:使用Hibernate5个核心接口

来源:互联网 发布:qq魅力值软件 编辑:程序博客网 时间:2024/05/20 04:14

这5个接口是:Configuration、SessionFactory、Session、Transaction、Query。通过这些接口,不仅可以对持久化对象(Persistent Object,PO)进行存取,还能进行事务控制。

Configuration config = new Configuration().configure();SessionFactory sessionFactory = config.buildSessionFactory();Session session = sessionFactory.openSession();Transaction ts = session.beginTransaction();Query query = session.createQuery("HQL");//...ts.commit(); //事务提交sessionFactory.closeSession(); //关闭Session

0 0