Hibernate系列3-----之修改

來源:互聯網
上載者:User

標籤:.com   部落格   hid   對象   click   屬性   加工   success   student   

只是修改測試類別,先看其他的代碼的同學,請翻看我的部落格Hibernate1,嘿嘿,我就在這不在重寫一遍來

1  @Test2     public void testhibernate() {3         updateStudent();  //修改學生4     } 
View Code
 1 private void updateStudent() { 2         //02Hibernate 儲存 3         //讀取大設定檔,擷取串連的資料庫資訊 4         Configuration cfg=new Configuration().configure(); 5         //3建立SessionFactory 6         SessionFactory factory=cfg.buildSessionFactory(); 7         //加工session 8         Session session=factory.openSession(); 9         //開啟事務10         Transaction tx=session.beginTransaction();11         //5Hibernate12         //根據session的方法做資料操作  修改13        //1.擷取Hibernate上下文跟蹤的對象14         Student student=session.load(Student.class,2);15         //2.對學生的屬性,類比重新賦值16         student.setName("久久");17         //3.調用update18     /*    session.update(student);*/   //髒檢查機制19         //提交事務20         tx.commit();21         //關閉session22         session.close();23         System.out.println("success  ok");24 25     }
View Code

知識點:這裡考查裡髒檢查機制(關於它的事迹,過幾天我會出部落格)

              所以session.update(student);之句話可以不用寫

Hibernate系列3-----之修改

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.