Hibernate Series 3-----Modification

Source: Internet
Author: User

Just modify the test class, first look at the other code of the classmate, please look at my blog Hibernate1, hey, I'm not here to rewrite it again

1 @Test 2      Public void testhibernate () {3         updatestudent ();  // Modify Student 4     
View Code
1 Private voidupdatestudent () {2         //02Hibernate Save3         //read the large configuration file to get the database information of the connection4Configuration cfg=NewConfiguration (). Configure ();5         //3 Creating Sessionfactory6Sessionfactory factory=cfg.buildsessionfactory ();7         //Processing Session8Session session=factory.opensession ();9         //Open TransactionTenTransaction tx=session.begintransaction (); One         //5Hibernate A         //make data manipulation changes according to the session method -        //1. Get the object for hibernate context tracking -Student Student=session.load (Student.class,2); the         //2. Simulate re-assignment of students ' properties -Student.setname ("Lasting"); -         //3. Call Update -     /*session.update (student);*/   //dirty Check mechanism +         //Commit a transaction - tx.commit (); +         //Close Session A session.close (); atSystem. out. println ("Success OK"); -  -}
View Code

Knowledge Point: Here to examine the dirty check mechanism (about its deeds, in a few days I will blog)

So Session.update (student), the words can not be written

Hibernate Series 3-----Modification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.