<property name="current_session_context_class">thread</property> 属性

转载至:http://www.cnblogs.com/a757956132/p/4309364.html

<property name="current_session_context_class">thread</property>
这个属性的作用:这样配置是本地jdbc事务配置,你通过getCurrentSession创建的session会绑定到当前线程

平时在单独使用hibernate的时候,习惯于配置属性

<property name="current_session_context_class">thread</property>
根据文档,这个是hibernate3.1以后的一个新扩展,目的在于可以让我们在某一个上下文环境(比如说当前线程)中可以通过 SessionFactory.getCurrentSession()得到同一个session会话.
 
后来当我们把spring,hibernate整合的时候,在spring的主配置文件当中,我们也习惯于带入这样的配置
<property name="hibernateProperties">
<props>
<prop key="hibernate.current_session_context_class">thread</prop>
,接下来在spring配置文件中,会使用spring2.x的声明式的方式来配置事务
<tx:advice id="txAdvice" transaction-manager="transactionManager">,<aop:pointcut,<aop:advisor等等配置指定哪些方法上由spring来管理hiberante的事务,这个时候我们试着运行一个类似于这样的方法
public void find() {
Session se = sf.getCurrentSession();
//此处不需要se.beginTransaction(),事务已经交由spring管理
Dept d = (Dept) se.get(Dept.class, new Long(12));
}
会得到一个异常: get is not valid without active transaction.
这个错误一般情况是因为由getCurrentSession得到的session中没有获得的transaction,我们一般要手动的调用se.beginTransaction(),来打开一个活动的事务.但是问题是,我们在spring的配置文件中不是已经通过aop,指定了此处由spring来管理事务吗,怎么还要手动处理事务?
 
答案: 
<prop key="hibernate.current_session_context_class">thread</prop>改为
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext</prop>(默认配置)
 
参考:
1. hibernate文档:
 
2.在hibernate中,thread,jta,manager的配置其实都是对应了3个hibernate的实现类
 
 
  3.在sessionFactory配置文件中
应将hibernate.current_session_context_class设为org.springframework.orm.hibernate3.SpringSessionContext(默认为此值)应当把session要绑定的上下文设置为由spring环境管理(因为我们的事务aop也是在spring范围中),这个时候spring中的事务配置才会起作用(当然,以前是thread上下文环境的session,而事务托管在spring上下文中,当然spring无法管理到thread上下文的session的事务咯)综上所述,其实仔细看 ThreadLocalSessionContext, JTASessionContext, ManagedSessionContext,SpringSessionContext我们都会发现,他们都实现了一个接口org.hibernate.context.CurrentSessionContext关于这个接口, 请参阅 org.hibernate.context.CurrentSessionContext 接口的 Javadoc,那里有关于它的契约的详细讨论。它定义了单一的方法,currentSession(),特定的实现用它来负责跟踪当前的上下文相关的会话  最后,我们知道,其实线程绑定也好,上下文绑定也好,最后都是,使用实现了 CurrentSessionContext接口的一个类,来跟踪session,然后我们通过这个类的对象来获得被它跟踪的session,以达到在我们定义的上下文环境中调用getCurrentSession方法获得的总是同一个session
非常抱歉,根据你提供的xfce4-session.xml配置文件内容,确实没有找到与"shutdown"相关的配置项。给你带来困扰,非常抱歉。 虽然没有找到通用的方式来禁用xfce4右键菜单中的"Log Out"选项,但你可以尝试使用以下方法来解决该问题: 1. 打开终端,并输入以下命令创建一个新的配置文件: ``` mkdir -p ~/.config/xfce4/xfconf/xfce-perchannel-xml/ touch ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml ``` 2. 使用文本编辑器(如nano或vim)编辑新创建的xfce4-panel.xml文件: ``` nano ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml ``` 3. 在打开的文件中,添加以下内容: ```xml <?xml version="1.0" encoding="UTF-8"?> <channel name="xfce4-panel" version="1.0"> <property name="global" type="empty"> <property name="disable-custom-menu" type="bool" value="true"/> </property> </channel> ``` 4. 保存并关闭文件。在nano编辑器中,按下Ctrl + X,然后输入"Y"确认保存,最后按下Enter键退出。 5. 重新启动xfce4面板,可以使用以下命令或注销并重新登录: ``` xfce4-panel --restart ``` 现在,右键菜单中的"Log Out"选项应该已经被禁用了。 请注意,这种方法禁用了整个面板的自定义菜单,因此可能会影响其他自定义菜单项。如果你只想禁用"Log Out"选项而保留其他自定义菜单功能,可能需要进一步的配置和调整。 希望这次能帮到你!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值