ようこそ、皆さん

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

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

          hibernate學習時,插入數據,log沒問題,但數據庫中沒有該條記錄

          在學習hibernate的時候,出現下列問題
             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是顯示成功的,但數據庫中沒有數據,可我已經session.flush()了啊?這是為什么?
          還有就是如果用transaction就可以了

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

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

          評論

          # re: hibernate學習時,插入數據,log沒問題,但數據庫中沒有該條記錄 2007-09-20 02:58 Unmi

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

          # re: hibernate學習時,插入數據,log沒問題,但數據庫中沒有該條記錄 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. 打開事務
          Session session = studentDAO.getSession();
          Transaction tran = session.beginTransaction();
          // 2. 生成對象
          dao.Student student = new dao.Student();
          student.setName("username");

          //studentDAO.save(student);

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

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

          }

          }
            回復  更多評論   

          # re: hibernate學習時,插入數據,log沒問題,但數據庫中沒有該條記錄 2007-10-31 21:43 Rex Mao

          對數據庫有更改,要調用commit();  回復  更多評論   

          # re: hibernate學習時,插入數據,log沒問題,但數據庫中沒有該條記錄 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.  回復  更多評論   

          平平淡淡,認認真真生活才是真。
          主站蜘蛛池模板: 南城县| 望谟县| 余江县| 万宁市| 寻乌县| 泌阳县| 托克托县| 峨眉山市| 丰顺县| 凤阳县| 咸阳市| 临洮县| 伊吾县| 平顶山市| 南京市| 张家界市| 白玉县| 乌鲁木齐市| 临高县| 白银市| 阿巴嘎旗| 松溪县| 来安县| 贡嘎县| 德江县| 张掖市| 腾冲县| 祁东县| 吉安市| 南投市| 辰溪县| 东山县| 祁连县| 宜州市| 长阳| 建瓯市| 镇坪县| 徐水县| 华安县| 资阳市| 女性|