ようこそ、皆さん

          開心幸福生活每一天。。。

          JPLT2が合格しましたが、會話と聴力はまだまだです。これからも、がんばれ!!!

          hibernate學(xué)習(xí)時,插入數(shù)據(jù),log沒問題,但數(shù)據(jù)庫中沒有該條記錄

          在學(xué)習(xí)hibernate的時候,出現(xiàn)下列問題
             Configuration config = new Configuration().configure();
             SessionFactory sessionFactory = config.buildSessionFactory();
             session = sessionFactory.openSession();
             TbmStudent student = new TbmStudent();
             student.setStudentNo("4587");
             student.setStudentName("name4587");
             student.setClassNo("B3");
             student.setChinesePoint(69);
             student.setMathematicsPoint(90);
             student.setEnglishPoint(80);
             student.setPhysicsPoint(60);
             student.setChemistryPoint(79);
             student.setModDate(new Date(System.currentTimeMillis()));
             session.save(student);
             session.flush();

          log是顯示成功的,但數(shù)據(jù)庫中沒有數(shù)據(jù),可我已經(jīng)session.flush()了啊?這是為什么?
          還有就是如果用transaction就可以了

          快快樂樂、認認真真生活才是真。

          posted on 2007-09-19 15:52 鮑佩 閱讀(1590) 評論(4)  編輯  收藏 所屬分類: hibernate

          評論

          # re: hibernate學(xué)習(xí)時,插入數(shù)據(jù),log沒問題,但數(shù)據(jù)庫中沒有該條記錄 2007-09-20 02:58 Unmi

          本來就是要事物控制的  回復(fù)  更多評論   

          # re: hibernate學(xué)習(xí)時,插入數(shù)據(jù),log沒問題,但數(shù)據(jù)庫中沒有該條記錄 2007-09-20 17:45 BeanSoft

          import org.hibernate.Session;
          import org.hibernate.Transaction;

          import dao.StudentDAO;


          public class DAOTest {

          /**
          * @param args
          */
          public static void main(String[] args) {
          StudentDAO studentDAO = new StudentDAO();
          // 1. 打開事務(wù)
          Session session = studentDAO.getSession();
          Transaction tran = session.beginTransaction();
          // 2. 生成對象
          dao.Student student = new dao.Student();
          student.setName("username");

          //studentDAO.save(student);

          // 3. 提交事務(wù)
          tran.commit();

          // 4. 列表
          java.util.List list = studentDAO.findAll();
          System.out.println(list.size());

          }

          }
            回復(fù)  更多評論   

          # re: hibernate學(xué)習(xí)時,插入數(shù)據(jù),log沒問題,但數(shù)據(jù)庫中沒有該條記錄 2007-10-31 21:43 Rex Mao

          對數(shù)據(jù)庫有更改,要調(diào)用commit();  回復(fù)  更多評論   

          # re: hibernate學(xué)習(xí)時,插入數(shù)據(jù),log沒問題,但數(shù)據(jù)庫中沒有該條記錄 2007-12-03 11:11 wxy

          add the flowing property
          <property name="hibernate.connection.autocommit">true</property>

          otherwise, get the JTA connection from j2ee server.  回復(fù)  更多評論   

          平平淡淡,認認真真生活才是真。
          主站蜘蛛池模板: 壶关县| 雅江县| 霍城县| 顺平县| 射阳县| 洱源县| 新河县| 南岸区| 都兰县| 福州市| 昆明市| 台东县| 南康市| 盐城市| 新营市| 大石桥市| 宁陕县| 南投市| 崇仁县| 增城市| 临武县| 孟连| 云南省| 千阳县| 防城港市| 大新县| 泰安市| 巴林右旗| 乡宁县| 曲周县| 丰镇市| 华宁县| 五华县| 江华| 神农架林区| 响水县| 东兴市| 平乡县| 新民市| 扶沟县| 安新县|