spring和hibernate整合使用getCurrentSession方法
来源:互联网 发布:查看端口是否的命令 编辑:程序博客网 时间:2024/06/06 07:16
spring和hibernate整合使用getCurrentSession()方法获得session实例时,一定记得在sessionFactory的bean中添加<prop key="hibernate.current_session_context_class">thread</prop>,如果你的事务时交给spring管理的,则就不要配置,不然就会报错:the save is not valid without active transaction.详细参见:http://blog.csdn.net/irelandken/article/details/7193123 这篇博客。
完整代码如下:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop> <!-- 使用getCurrentSession()方法,必须配置此属性 -->
</props>
</property>
<property name="mappingResources">
<list>
<value>com/hibernate/pojo/CirFriends.hbm.xml</value>
<value>com/hibernate/pojo/CirInformation.hbm.xml</value>
<value>com/hibernate/pojo/CirUser.hbm.xml</value>
<value>com/hibernate/pojo/CirRemark.hbm.xml</value></list>
</property>
</bean>
- spring和hibernate整合使用getCurrentSession方法
- Hibernate整合进spring--使用hibernateTemplate.getSessionFactory().getCurrentSession()理解
- spring+Hibernate openSession()和getCurrentSession()
- Hibernate中使用GetCurrentSession()方法
- hibernate getCurrentSession和Spring事务管理集成
- Hibernate注解使用和spring整合
- 使用spring整合hibernate
- hibernate openSession和getCurrentSession
- hibernate opensession()和getCurrentSession()
- 整合Spring和Hibernate
- Hibernate和Spring整合
- spring和hibernate整合
- Spring和Hibernate整合
- Spring和Hibernate整合
- spring和Hibernate 整合
- 整合Hibernate和Spring
- 整合Hibernate和Spring
- spring和Hibernate整合
- 如何带新近的程序员
- java设计模式之工厂模式
- 可能导致Loadrunner检查点中savecount为0的分析
- 第3章产品经理与项目经理不同——区别二者
- Android Menu
- spring和hibernate整合使用getCurrentSession方法
- i++与++i的区别与性能差异
- cron表达式详解
- 从4行代码看右值引用
- 推送
- 决定成败的,绝对不只是细节
- hdu1402A * B Problem Plus(NTT)
- 蓝牙学习之旅——低功耗蓝牙之广播报文SCAN_RSP
- Mac系统java环境搭建