会话工厂尚未初始化

时间:2012-03-31 07:44:59

标签: java hibernate

public Session openTxCoreSession()
    {
        try
        {
            System.out.println("openTxCoreSession() start...");

            TxCoreSessionFactory sessionFactory =
                TxCoreSessionFactory.getInstance("conf/txcore.cfg.xml");
            System.out.println("Session factory created....");

            Session session = sessionFactory.openSession();

            coreTransaction = session.beginTransaction();
            coreConnection = session.connection();
            System.out.println("session created");
            return session;
        }

        catch (Exception e)
        {
            System.out.println(e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

以下是例外情况 -

The session factory has not been initialized.
java.lang.RuntimeException: The session factory has not been initialized.
at com.uniteller.txcore.base._BaseRootDAO.getSessionFactory(_BaseRootDAO.java:86)
at com.uniteller.txcore.base._BaseRootDAO.createSession(_BaseRootDAO.java:116)
at com.uniteller.txcore.TxCoreSessionFactory.openSession(TxCoreSessionFactory.java:77)
at com.uniteller.tools.databroker.DataBroker.openTxCoreSession(DataBroker.java:674)
at com.uniteller.tools.databroker.DataBroker.run(DataBroker.java:90)
at com.uniteller.tools.databroker.DataBrokerImplementer.main(DataBrokerImplementer.java:27)

1 个答案:

答案 0 :(得分:0)

本准则可以帮助您。

SessionFactory sessionFactory=new Configuration().Configure("conf/txcore.cfg.xml").buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction=session.beginTransaction();