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"
>
<property name="dataSource" ref="liferayDataSource" />
</bean>
修改后的定义:
<bean id="liferayHibernateSessionFactory"
>
<property name="dataSource" ref="liferayDataSource" />
<property name="hibernateProperties">
<props>

<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
</bean>