import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.junit.Test;import com.opensymphony.xwork2.interceptor.annotations.After;import com.opensymphony.xwork2.interceptor.annotations.Before;public class HibernateUtil { private SessionFactory sessionFactory; private Session session; private Transaction transaction; @Before public void init() { // 創(chuàng)建配置對象 Configuration config = new Configuration().configure(); // 創(chuàng)建回話工廠對象 sessionFactory = config.buildSessionFactory(); // 會話對象 session = sessionFactory.openSession(); // 開啟事務(wù) transaction = session.beginTransaction(); } @After public void destory() { transaction.commit();// 提交事務(wù) session.close();// 關(guān)閉會話 sessionFactory.close();// 關(guān)閉會話工廠 } @Test public void testSaveUser(){ User u=(User)session.get(User.class, 100000); System.out.println(u.getUsername()); }}?大佬們,求解為什么會出現(xiàn)java.lang.NullPointerException,提示是User u=(User)session.get(User.class, 100000);這個地方出錯,但是我排查不出來。。
添加回答
舉報
0/150
提交
取消