Liferay sessionFactory.getCurrentSession()报错问题
来源:互联网 发布:淘宝都是支付宝登录吗 编辑:程序博客网 时间:2024/06/11 06:34
刚开始研究liferay不久,不过对liferay的功能和用的技术真多比较佩服.不过对于开发人员来说要深入了解那么的技术的不是那么容易的事情.
liferay的资料相对较少,不过去官方的论坛和wiki里面找一些东西.
最近在使用liferay的plugin portlet开发方式.
最简单的功能就是直接从数据库查询数据,插入数据等.
插入数据的话用liferay的build service工具就能自动提供接口不用那么麻烦.
不过查询的时候从BasePersistenceImpl类的openSession()的时候报了下面的错误.
com.liferay.portal.kernel.exception.SystemException: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at com.test.finder.service.persistence.TestEntryFinderImpl.findByNoAssets(TestEntryFinderImpl.java:256)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at com.liferay.portal.dao.shard.ShardAdvice.invokePersistence(ShardAdvice.java:205)
at sun.reflect.GeneratedMethodAccessor524.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy348.findByNoAssets(Unknown Source)
郁闷了好几天.找了好些liferay的东西看也不知道解决办法.
最近跟踪代码,发现里面是sessionFactory.getCurrentSession()这个方法报错.
当时想你报错那我就不用你好了,用Session openNewSession(Connection connection)这个方法好了.
openNewSession这个方法倒是能够正常访问了,但这个是每次都打开一个新连接,然后关闭.
还是感觉用springde东西比较好.
没办法回到sessionFactory.getCurrentSession()为什么出错上来,在网上找了很久,才发现了解决办法.
service builder执行后的默认定义.
<bean id="liferayHibernateSessionFactory"
class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="liferayDataSource" />
</bean>
修改后的定义:
<bean id="liferayHibernateSessionFactory"
class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration">
<property name="dataSource" ref="liferayDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>
需要把这个上下文定义为线程.主要还是对hibernate和spring不熟悉,花费了不少时间.
- Liferay sessionFactory.getCurrentSession()报错问题
- sessionFactory.getCurrentSession()报错
- SessionFactory.getCurrentSession()
- getCurrentSession()报错
- 解决getCurrentSession()spring无法注入SessionFactory的问题
- SessionFactory.getCurrentSession…
- sessionFactory.getCurrentSession()说明
- sessionFactory.getCurrentSession()说明
- sessionFactory.openSession()和sessionFactory.getCurrentSession()区别
- sessionFactory().getCurrentSession()和sessionFactory().openSession的区别
- 【转】Hibernate SessionFactory().getCurrentSession()猫腻
- 新Hibernate SessionFactory().getCurrentSession()猫腻
- 新Hibernate SessionFactory().getCurrentSession()猫腻
- sessionfactory.getcurrentsession()获取不到session
- 遇到问题---java--hibernate多线程中使用getCurrentSession报错innerSetException
- SessionFactory.getCurrentSession与openSession的区别
- SessionFactory.getCurrentSession与openSession的区别
- SessionFactory.getCurrentSession与openSession的区别
- Linux 内核使用的 GNU C 扩展
- 2010.8 DeCoder
- JPA整合Spring配置数据源
- WIN32API函数实现串口
- Linux应用程序开发
- Liferay sessionFactory.getCurrentSession()报错问题
- 普通pojo类实现任务调度
- 让你的网站在IE9和Win7任务栏上更闪亮
- struts2.1文件上传
- div 居中
- struts2.1文件下载
- Magento 布局(XML)原理解析
- man手册的配置
- 【百科】吴银根