首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >钩子中的自定义服务构建器中的会话工厂未实例化

钩子中的自定义服务构建器中的会话工厂未实例化
EN

Stack Overflow用户
提问于 2014-10-13 17:57:52
回答 2查看 519关注 0票数 0

我正在尝试在liferay 6.1钩子中创建一个新的实体,以自定义日历portlet。我使用服务构建器创建了一个引用Liferay6.1文档(https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/service-builder-liferay-portal-6-1-dev-guide-en)的新实体。构建服务是成功的。这是生成的portlet-spring.xml文件。

代码语言:javascript
复制
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="test.service.CalTimeSlotsLocalService" class="test.service.impl.CalTimeSlotsLocalServiceImpl" />
    <bean id="test.service.CalTimeSlotsService" class="test.service.impl.CalTimeSlotsServiceImpl" />
    <bean id="test.service.persistence.CalTimeSlotsPersistence" class="test.service.persistence.CalTimeSlotsPersistenceImpl" parent="basePersistence" />
</beans>

我在xxLocalServiceImpl类中添加了一个自定义函数,如下所示:

代码语言:javascript
复制
public List<String> getTimeValues() throws SystemException {
List<String> timeValues = new ArrayList<String>();
CalTimeSlotsPersistence calTimeSlotPersist = new CalTimeSlotsPersistenceImpl();
for (CalTimeSlots calTimeSlot : calTimeSlotPersist.findAll()) {
timeValues.add(calTimeSlot.getTimeValue());
}
return timeValues;
}

实体已在数据库中正确创建。但是,上面的findAll函数抛出了一个空指针异常。

代码语言:javascript
复制
09:41:03,749 ERROR [http-bio-8080-exec-4][BasePersistenceImpl:186] Caught unexpected exception java.lang.NullPointerException
09:41:03,782 ERROR [http-bio-8080-exec-4][IncludeTag:253] Current URL /web/guest/what-we-do?p_p_id=86&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&controlPanelCategory=portlet_86&_86_redirect=%2F&_86_struts_action=%2Fportlet_configuration%2Fedit_configuration&_86_returnToFullPageURL=%2F&_86_portletResource=8&_86_previewWidth=&tabs2=display-settings generates exception: null
09:41:03,787 ERROR [http-bio-8080-exec-4][IncludeTag:154] java.lang.NullPointerException
at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.closeSession(BasePersistenceImpl.java:74)
at test.service.persistence.CalTimeSlotsPersistenceImpl.findAll(CalTimeSlotsPersistenceImpl.java:517)
at test.service.persistence.CalTimeSlotsPersistenceImpl.findAll(CalTimeSlotsPersistenceImpl.java:416)
at test.service.impl.CalTimeSlotsLocalServiceImpl.getTimeValues(CalTimeSlotsLocalServiceImpl.java:55)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)

当我尝试调试这个问题时,我发现会话工厂没有实例化,并且始终为空。我是不是漏掉了什么?我该如何解决这个问题呢?

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2015-01-02 10:26:45

您可以在CalTimeSlotsImpl类中使用getCalTimeSlotsPersistence().findAll()

票数 0
EN

Stack Overflow用户

发布于 2015-01-03 18:03:12

试试这条路

代码语言:javascript
复制
public List<String> getTimeValues() throws SystemException {
    List<String> timeValues = new ArrayList<String>();
    for (CalTimeSlots obj : getCalTimeSlotses(0, getCalTimeSlotsesCount())) {
        timeValues.add(obj.getTimeValue());
    }
    return timeValues;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26337257

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档