`
nmw02229
  • 浏览: 8714 次
社区版块
存档分类
最新评论

Liferay sessionFactory.getCurrentSession()报错问题 (转)

阅读更多


刚开始研究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笔记.doc

    liferay笔记.doc

    Liferay合集.zip

    中文文档部分可能包含了Liferay的基础教程、最佳实践、常见问题解答等,这些文档对于中文环境下的学习者来说尤其方便,能够快速理解Liferay的关键概念,解决在使用过程中遇到的问题。 通过学习这些资料,开发者可以...

    liferay7.0 com.liferay.blade.cli

    Liferay7.0 通过JPM安装Blade CLi时[ZipFile.open] error in opening zip file ,将此包下载至本地,执行安装命令可解决:http://blog.csdn.net/u012551585/article/details/54346457

    Liferay in action

    Liferay is a different portal. 10分下载的, 打包5折提供下载. Part 1 Introduction to Liferay 1. Liferay is a different portal 2. Getting started with the Liferay development platform Part 2 Adding ...

    Packtpub.Liferay.User.Interface.Development.Nov.2010.rar

    标题 "Packtpub.Liferay.User.Interface.Development.Nov.2010.rar" 暗示这是一款关于Liferay用户界面开发的电子书资源,由Packt Publishing在2010年11月出版。Liferay是一种开源的企业级门户平台,广泛用于构建企业...

    liferay环境搭建.doc

    如果你想让JAR包在部署后直接出现在Liferay的Tomcat目录下,可以修改工作区的`gradle.properties`文件,添加属性`liferay.workspace.home.dir`指向Liferay安装目录。 2. **Service Builder使用** - 创建一个新的...

    liferay资料\Liferay.Portal.Enterprise.Intranets.April.2008

    根据给定文件的信息,我们可以提炼出关于Liferay Portal Enterprise Intranets的相关知识点,这主要涉及企业内部网构建、版权信息、作者与出版商详情以及作者背景等关键领域。 ### Liferay Portal Enterprise ...

    com.liferay.util.ParamUtil.java

    其中,`com.liferay.util.ParamUtil.java`是Liferay框架中的一个核心工具类,主要用于处理请求参数。本文将详细探讨`ParamUtil`类及其在实际开发中的应用。 `ParamUtil`类位于`com.liferay.util`包下,是Liferay...

    Packtpub.Liferay.Portal.6.Enterprise.Intranets.May.2010.rar

    《Packtpub.Liferay.Portal.6.Enterprise.Intranets.May.2010》这本书聚焦于Liferay Portal 6版本在构建企业级内网解决方案中的应用。Liferay Portal是一款开源的企业级门户平台,广泛用于创建、管理和整合数字体验...

    using-liferay-portal-6.2.pdf

    1 What is Liferay? 1 1.1 Building a site with Liferay Web Content . . . . . . . . . . . . . . . . . 1 1.2 Using Liferay Portal as a collaborative platform . . . . . . . . . . . . . . 6 1.3 Using ...

    Packt.Publishing.Liferay.Portal.Enterprise.Intranets

    本书《Packt.Publishing.Liferay.Portal.Enterprise.Intranets》由Packt Publishing出版,作者为Jonas X. Yuan,主要介绍了如何利用Liferay Portal搭建企业内部网络。该书不仅提供了理论基础,还包含了大量实用案例...

    liferay.properties中的几处说明

    在Liferay Portal中,`liferay.properties`是一个关键的配置文件,它定义了系统的各种行为和设置。在本文中,我们将深入探讨这个文件中与页面可见性、我的位置portlet(My Places Portlet)以及用户协议展示相关的...

    liferay-portal-service.jar

    import com.liferay.portal.kernel.util.StringBundler; StringBundler jsonStr1 = new StringBundler(150); 操作如StringBuilder,相同

    Liferay.Portal.Enterprise.Intranets.April.2008.pdf

    《Liferay Portal Enterprise Intranets April 2008》是关于Liferay门户平台的一本专著,出版于2008年4月,对于理解并掌握Liferay在企业内部网络(Intranets)中的应用具有重要价值。Liferay Portal是一款开源的企业...

    liferay-portlet-icefaces-archetype-6.1.30.zip

    commons-configuration-gae.zip,配置的实现(由apache commons配置库提供),使用google app engine datastore api存储配置参数;配置的实现(由apache commons配置库提供),使用google app engine datastore api...

    Liferay时,遇到的问题及解决方法

    Liferay时,遇到的问题及解决方法; JavaProject 固定值设定 去掉Liferay中的“您的请求已成功完成!"的提示 portlet引用资源方法....

    liferay开发文档.pdf

    配置文件包括portal.properties、portlet.properties、liferay.properties等。 * Liferay 配置文件的种类 + portal.properties + portlet.properties + liferay.properties * Liferay 配置文件的作用 + 管理...

    liferay portlet

    开发Liferay Portlet时,可以选择继承Liferay提供的基类,如com.liferay.portlet.LiferayPortlet,或者直接继承JSR标准的javax.portlet.GenericPortlet。 在部署Liferay应用到一个新的Tomcat服务器时,需要注意一些...

Global site tag (gtag.js) - Google Analytics