当前位置:网站首页>Hibernate entity class curd, transaction operation summary
Hibernate entity class curd, transaction operation summary
2022-06-25 23:34:00 【_ Qilixiang】
Full of dry goods !
Catalog
Hibernate Transaction operation of
Add operation
save() Method


saveOrUpdate() Method

Inquire about

result :

modify

Use save() The method is completely consistent with this effect :

Direct... Is not recommended new Object readjustment update() Method , This results in a null value .
Delete operation
The first one is : according to ID Inquire about , Returns the object , call delete() Method to delete the object

The second kind :new object , call delete() Method to delete the object
Save or update
saveOrUpdate()
Instantaneous time : This method does the add operation

Persistent state : Modify the operating

In managed status : Modify the operating

Tool class encapsulation
package com.wl.utils;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/*
* Extract tool class
*/
public class HibernateUtils {
private static final Configuration cfg ;
private static final SessionFactory sessionFactory ;
static{
cfg = new Configuration();
cfg.configure();
sessionFactory = cfg.buildSessionFactory();
}
// This method returns this sessionFactory object
public static SessionFactory getSessionFactory(){
return sessionFactory;
}
}
Object state of entity class
Instantaneous state
No in object id value , Object and the session There's no connection .
Persistence state
Among objects id value , Object and the session relation
Trusteeship
Among objects id value , Object and the session There's no connection
Hibernate Transaction operation of
Rule writing of transaction code
try{
Open transaction
Commit transaction
}catch(){
Roll back the transaction
}finally{
Closing transaction
}
边栏推荐
- [Axi] interpretation of Axi protocol atomic access
- OpenJudge NOI 2.1 15:Counterfeit Dollar
- 二进制、16进制、大端小端
- 【AXI】解读AXI协议乱序机制
- Technology blog site collection
- Applets - view and logic
- Xinchida nd04 nd04c nrf52832 (52810) ble module (low power Bluetooth communication module) at command test
- Implementation of sequence table: static and dynamic
- 社招两年半10个公司28轮面试面经(含字节、拼多多、美团、滴滴......)
- Leetcode(435)——无重叠区间
猜你喜欢

Kubernetes cluster construction of multiple ECS

转载: QTableWidget详解(样式、右键菜单、表头塌陷、多选等)

RK3568+鸿蒙工控板工业网关视频网关解决方案
Why is BeanUtils not recommended?

How to add cartoon characters to the blog park?

C language (I)

How to use drawing comparison function in CAD

漏刻有时API接口实战开发系列(13):小鹅通云服务PHP-API二维数组传参解决方案

Visual studio code create minimal web API (asp.net core)

问题记录与思考
随机推荐
What is Unified Extensible Firmware Interface (UEFI)?
Applets - view and logic
信息学奥赛一本通 1353:表达式括号匹配(stack) | 洛谷 P1739 表达式括号匹配
Implementation of sequence table: static and dynamic
Svn icon disappearing solution
音频基础知识以及PCM转WAV
After xampp restarts, the MySQL service cannot be started.
C. Fibonacci Words-April Fools Day Contest 2021
Why is the frame rate calculated by opencv wrong?
Multithreaded learning 2- call control
解决‘tuple‘ object has no attribute ‘lower‘
What is CDN acceleration
问题记录与思考
Efr32bg22 ble module (low power Bluetooth communication module) at command test
Idea common plug-ins
Core points of assembly language
【opencv450-samples】inpaint 使用区域邻域恢复图像中的选定区域
cookie、session、token
【AXI】解读AXI协议乱序机制
Konva series tutorial 2: drawing graphics