0

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

<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 类中添加了一个自定义函数,如下所示:

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 函数会引发空指针异常。

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)

当我尝试调试问题时,我发现会话工厂未实例化并且始终为空。有什么我想念的吗?我该如何解决这个问题?

谢谢你。

4

2 回答 2

0

您可以getCalTimeSlotsPersistence().findAll()CalTimeSlotsImpl课堂上使用

于 2015-01-02T02:26:44.507 回答
0

试试这个方法

public List<String> getTimeValues() throws SystemException {
    List<String> timeValues = new ArrayList<String>();
    for (CalTimeSlots obj : getCalTimeSlotses(0, getCalTimeSlotsesCount())) {
        timeValues.add(obj.getTimeValue());
    }
    return timeValues;
}
于 2015-01-03T10:03:12.057 回答