Common Code block templates, get and load differences, session. Get (,) parameter explanations, session method summary

Source: Internet
Author: User

 Steps for setting the template code: WINDOW> JAVA> templates> New
Template code
session = hibernateutils. opensession (); try { hibernateutils. starttransaction (); /** * Specific Business Code */ hibernateutils. committransaction () ;} catch (exception e) {hibernateutils. rollbacktransaction (); throw New runtimeexception (e) ;}< br> =================================================== =============< br>
Difference between hibernate get and Load
 
The fundamental difference between get and load. In a word, Hibernate considers the load method to exist in the database,
You can safely use a proxy to delay loading. If a problem is found during use, you can only throw an exception. For the get method,
Hibernate must obtain real data; otherwise, null is returned.
 
========================================================== ============
 

Session. Get (,) parameter explanation
 
Session. Get (user.Class, 2)// Search for data with ID = 2 in the user object
 
 

 

 
First parameter: object type to be searched
Second parameter: Corresponding id Primary Key
 
========================================================== ============
 
 
 
Session method summary
 
 
 1   Session. Save (Object object); added  2  Session. Update (Object object); Modify  3   Session. saveorupdate (Object object); Modify if the primary key field has a value, and add if no value exists.  4   Session. Update (Object object );  5   Session. Delete (Object object); Delete  6   Session. createquery (string hql); query by hql statement  7   Session. createcriteria (class entityclass); Queries QBC by entity  8   Session. Load (class entityclass, serialize ID); query by ID to delay loading. 9 Session. Get (class entityclass, serialize ID); query by ID and load immediately.
 
 

 

 
 

 

 

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.