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