当前位置: 代码迷 >> J2EE >> Hibernate 一点有关问题
  详细解决方案

Hibernate 一点有关问题

热度:23   发布时间:2016-04-22 00:22:42.0
Hibernate 一点问题
Java code
public class HibernateUtil {    private static Configuration cfg;    private static ServiceRegistry sr;    private static SessionFactory sf;    static {        try {            cfg = new Configuration();            cfg.configure();            sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();            sf = cfg.buildSessionFactory(sr);        } catch (Exception e) {            // TODO: handle exception            e.printStackTrace();        }    }        public static Configuration getConfiguration() {        return cfg;    }        public static SessionFactory getSessionFactory() {        return sf;    }        public static Session getSession() throws HibernateException {        return sf.getCurrentSession();    }}public class EcrPartsDaoImpl extends HibernateUtil implements EcrPartsDao {    //添加数据    public boolean addData(EcrParts ecr) {        boolean flag = false;        Transaction tx = null;        try {            tx = getSession().beginTransaction();            getSession().save(ecr);            tx.commit();            flag = true;        } catch (Exception e) {            // TODO: handle exception            tx.rollback();            e.printStackTrace();        } finally {            getSessionFactory().close();        }        return flag;    }}

一到tx = getSession().beginTransaction();这里就出现异常了。不知道怎么回事,求解

------解决方案--------------------
报什么异常?
------解决方案--------------------
连接好像没打开吧。
  相关解决方案