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.