我正在尝试在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)
当我尝试调试问题时,我发现会话工厂没有实例化,并且始终为null。 有什么我想念的吗?我该如何解决这个问题?
谢谢。
答案 0 :(得分:0)
您可以在getCalTimeSlotsPersistence().findAll()
班级
CalTimeSlotsImpl
答案 1 :(得分: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;
}