Hibernate2 ---- query a single record, hibernate2 ---- single record
1. Based on the completed basic Hibernate1 case, let's write a query and modify and delete it. You can learn about it for basic students.
Only rewrite the code of the test class
1 private void findStudent () {2 // 02 Hibernate save 3 // read the large Configuration file and obtain the connected database information 4 Configuration cfg = new Configuration (). configure (); 5 // 3 create SessionFactory 6 SessionFactory factory = cfg. buildSessionFactory (); 7 // process session 8 Session session = factory. openSession (); 9 // start Transaction 10 Transaction tx = session. beginTransaction (); 11 // 5Hibernate12 // perform data operation search based on the session Method 13 Student student = session. get (Student. class, 2); 14 System. out. println (student. getName (); 15 // submit the transaction 16 tx. commit (); 17 // close session18 session. close (); 19 System. out. println ("success OK"); 20 21} View Code
There is a small knowledge:
// Perform data operation search based on the session Method
Student student = session. get (Student. class, 2 );
What does the Class <T> mean?