Hibernate2 ---- query a single record, hibernate2 ---- single record

Source: Internet
Author: User

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?



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.