当前位置:网站首页>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
}
边栏推荐
- Windows redis installation and simple use
- konva系列教程2:绘制图形
- 【AXI】解读AXI协议原子化访问
- Leetcode (605) -- flower planting
- Idea auto generator generates constructor get/set methods, etc
- 音频基础知识以及PCM转WAV
- Beacon realizes asset management and indoor positioning based on 5.2 ultra-low power Bluetooth module efr32 (bg22ax)
- Repoptimizer: it's actually repvgg2
- After xampp restarts, the MySQL service cannot be started.
- C1. k-LCM (easy version)-Codeforces Round #708 (Div. 2)
猜你喜欢

How to add cartoon characters to the blog park?

UE4 学习记录一 创建角色,并控制其移动

CTS RTS RX TX in serial port flow control UART (direct communication between serial port module and MCU)

Kotlin空指针Bug

hiberate实体类CURD、事务操作汇总

毕业旅行 | 伦敦5日游行程推荐

Fegin client entry test

After xampp restarts, the MySQL service cannot be started.

Idea FAQ collection
![[opencv450 samples] inpaint restores the selected region in the image using the region neighborhood](/img/36/8ad6034473382f66f315eb70440711.png)
[opencv450 samples] inpaint restores the selected region in the image using the region neighborhood
随机推荐
Episode 3: thread synchronization using thread lock
Day4 branch and loop summary and operation
CDN加速是什么
UE4_UE5结合offline voice recognition插件做语音识别功能
28 rounds of interviews with 10 companies in two and a half years (including byte, pinduoduo, meituan, Didi...)
首个大众可用PyTorch版AlphaFold2复现,哥大开源OpenFold,star量破千
Leetcode(435)——无重叠区间
库项目和App项目中清单文件的包名不要相同
Recently prepared to translate foreign high-quality articles
Ad20 learning notes I
OBS-Studio-27.2.4-Full-Installer-x64. Exe Download
Xampp重启后,MySQL服务就启动不了。
Comp2913 database
Kubernetes cluster construction of multiple ECS
【opencv450-samples】inpaint 使用区域邻域恢复图像中的选定区域
QComboBox下拉菜单中有分隔符Separator时的样式设置
我的vscode
[Axi] interpretation of Axi protocol atomic access
go中全类型等值判断解析&综合汇总
Idea shortcut