-
关于事务嵌套
- package com.censoft.portlets.db.base;
- import com.censoft.portlets.db.DbTools;
- import net.sf.hibernate.*;
- import net.sf.hibernate.cfg.*;
- public class HibernateSession {
-
- public static final ThreadLocal sessionContext = new ThreadLocal();;
- private Session session;
- private int level;
-
- public static Session currentSession(String cfgFilePath); throws Exception {
- HibernateSession hSession = (HibernateSession);sessionContext.get();;
- if (hSession == null);
- {
- hSession = new HibernateSession();;
- SessionFactory factory = DbTools.getSessionFactory(cfgFilePath);;
- hSession.session = factory.openSession();;
- hSession.level = 0;
- sessionContext.set( hSession );;
- }
- hSession.level++;
- return hSession.session;
- }
-
- public static void closeSession(); throws Exception {
- HibernateSession hSession = (HibernateSession);sessionContext.get();;
- if (hSession == null);
- {
- return;
- }
- hSession.level--;
- if (hSession.level <= 0);
- {
- if (hSession.session != null && hSession.session.isOpen(););
- {
- hSession.session.close();;
- }
- sessionContext.set( null );;
- }
- }
-
- }
- 码并不是nested transaction只是在同一个线程里只使用一个session对象。事务嵌套是一种概念,SUN的J2EE规范的确没有实现事务嵌套。但其实我们使用flat transaction其实也已经足够了。
- 这种做法有点象COM里引用计数。
我在想,事实业务中是否需要嵌套事务。如果可能的话,尽量把做法向简单那里靠。
-
相关阅读:
【科普】.NET 泛型
吐槽,青岛科技大学真他妈操蛋
c# 数组和集合精讲
c# System.Text.Json 精讲
.NET 5的System.Text.Json的JsonDocument类讲解
c#中Array,ArrayList 与List<T>的区别、共性与转换
代码是怎么运行的?
.NET6使用DOCFX根据注释自动生成开发文档
spring通过注解注册bean的方式+spring生命周期
莫比乌斯反演
-
原文地址:https://www.cnblogs.com/anuoruibo/p/2410211.html
Copyright © 2020-2023
润新知