0
我開始使用openSessionInViewFilter來管理會話。我將我的服務方法註釋爲@Transactional作爲clossing會話,但下面的異常開始出現。當我的註釋服務方法結束時會引發此異常,這也可以在堆棧跟蹤中看到。我使用Spring 3, Hibernate 3, jsf 1.2
。Spring事務+休眠類拋出異常
堆棧跟蹤我的web.xml
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Service
@Service("zukService")
@Transactional
public class ZukServiceImpl extends AbstractService implements ZukService {
@Autowired
private DuniversalBenefitsPrescriptionDAO prescriptionDAO;
@Override
public List<DuniversalBenefitsPrescription> getListOfPrescriptions(final BenefitsSearchPrescriptionCriteria criteria) {
final List<DuniversalBenefitsPrescription> transcriptionList = prescriptionDAO
.getPaymentPrescriptionsByZukAndDate(criteria);
return transcriptionList;
//IN THIS PLACE PROBLEM OCCUR
}
}
DuniversalBenefitsPrescription
public class DuniversalBenefitsPrescription implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private Integer zukNumber;
private String policyNumber;
private String insureeName;
private String insureeSurname;
private Long identificationNumber;
private Double amountFromEmployer;
private Double amountFromEmployee;
private Date insuranceDate;
private Short frequency;
private Date validFrom;
private Date validTo;
private Short opken1;
private Short opken2;
private Short opken3;
private Double totalAmount;
private Long startOfBenefit;
private Long endOfZukValidity;
private String proposalNumber;
private Date dueDate;
private String buyoutTerm;
..getters and setters
}
的
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.Long
at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36)
at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:52)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:89)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2184)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2558)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2494)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2821)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:145)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:924)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:737)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy57.getListOfPrescriptions(Unknown Source)
at cz.generali.benefits.bean.TranscriptionBean.getPrescriptions(TranscriptionBean.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:171)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
at javax.faces.component.UIData.getValue(UIData.java:1389)
at org.ajax4jsf.component.UIDataAdaptorBase.getValue(UIDataAdaptorBase.java:1647)
at org.ajax4jsf.component.SequenceDataAdaptor.getDataModel(SequenceDataAdaptor.java:65)
at org.ajax4jsf.component.SequenceDataAdaptor.createDataModel(SequenceDataAdaptor.java:59)
at org.richfaces.component.UIDataTable.createDataModel(UIDataTable.java:121)
at org.ajax4jsf.component.UIDataAdaptorBase.getExtendedDataModel(UIDataAdaptorBase.java:621)
at org.ajax4jsf.component.UIDataAdaptorBase.getRowIndex(UIDataAdaptorBase.java:311)
at javax.faces.component._ComponentUtils.idsAreEqual(_ComponentUtils.java:136)
at javax.faces.component._ComponentUtils.findComponent(_ComponentUtils.java:109)
at javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:465)
at org.ajax4jsf.renderkit.RendererUtils.findUIComponentBelow(RendererUtils.java:1072)
at org.ajax4jsf.renderkit.RendererUtils.findUIComponentBelow(RendererUtils.java:1079)
at org.ajax4jsf.renderkit.RendererUtils.findComponentFor(RendererUtils.java:1042)
at org.ajax4jsf.renderkit.RendererUtils.findComponentFor(RendererUtils.java:1014)
at org.richfaces.component.util.HtmlUtil.expandIdSelector(HtmlUtil.java:75)
at org.richfaces.renderkit.ComponentControlRendererBase.replaceClientIds(ComponentControlRendererBase.java:90)
at org.richfaces.renderkit.ComponentControlRendererBase.writeScript(ComponentControlRendererBase.java:122)
at org.richfaces.renderkit.html.ComponentControlRenderer.doEncodeEnd(ComponentControlRenderer.java:129)
at org.richfaces.renderkit.html.ComponentControlRenderer.doEncodeEnd(ComponentControlRenderer.java:136)
at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:649)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:534)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:511)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlLinkRendererBase.encodeChildren(HtmlLinkRendererBase.java:144)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:627)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.richfaces.renderkit.html.ToolBarGroupRenderer.renderChild(ToolBarGroupRenderer.java:74)
at org.richfaces.renderkit.html.ToolBarGroupRenderer.encodeChildren(ToolBarGroupRenderer.java:56)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:627)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.richfaces.renderkit.html.ToolBarRendererBase.encodeChildren(ToolBarRendererBase.java:118)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:627)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:250)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:257)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:187)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:384)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at cz.generali.benefits.util.UserLogFilter.doFilter(UserLogFilter.java:37)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at cz.generali.benefits.security.UserProfileStubFilter.doFilter(UserProfileStubFilter.java:43)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at cz.generali.benefits.security.FirstLoginFilter.doFilter(FirstLoginFilter.java:34)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:724)
部分
的hbm.xml
<hibernate-mapping>
<class name="cz.generali.czgpolinfo.dao.syn.DuniversalBenefitsPrescription">
<subselect>
SELECT
PLAT.ID AS ID,ZUK.ZUKNR,SML.VB,SML.POLNR,SML.ZAHLART,COR.FIZAHL,PLAT.GESAMTBETRAG,COR.KLIZAHL,OS.RDC,
OS.FAMNAME,OS.VORNAME,PLAT.OPKENN1,PLAT.OPKENN2,PLAT.OPKENN3,PLAT.PRAEMIEVON,PLAT.PRAEMIEBIS,ZUK.WERTVON,ZUK.WERTBIS,SML.FREMDPOLNR,SML.BEZBIS,RP.TEXT
FROM ...
</subselect>
<id name="id" type="java.lang.Long">
<column name="ID"/>
<generator class="assigned"/>
</id>
<property generated="never" lazy="false" name="zukNumber" type="java.lang.Integer">
<column name="ZUKNR"/>
</property>
<property generated="never" lazy="false" name="policyNumber" type="java.lang.String">
<column name="POLNR"/>
</property>
<property generated="never" lazy="false" name="insureeName" type="java.lang.String">
<column name="VORNAME"/>
</property>
<property generated="never" lazy="false" name="insureeSurname" type="java.lang.String">
<column name="FAMNAME"/>
</property>
<property generated="never" lazy="false" name="identificationNumber" type="java.lang.Long">
<column name="RDC"/>
</property>
<property generated="never" lazy="false" name="amountFromEmployer" type="java.lang.Double">
<column name="FIZAHL"/>
</property>
<property generated="never" lazy="false" name="amountFromEmployee" type="java.lang.Double">
<column name="KLIZAHL"/>
</property>
<property generated="never" lazy="false" name="insuranceDate" type="java.util.Date">
<column name="VB"/>
</property>
<property generated="never" lazy="false" name="frequency" type="java.lang.Short">
<column name="ZAHLART"/>
</property>
<property generated="never" lazy="false" name="validFrom" type="java.util.Date">
<column name="PRAEMIEVON"/>
</property>
<property generated="never" lazy="false" name="validTo" type="java.util.Date">
<column name="PRAEMIEBIS"/>
</property>
<property generated="never" lazy="false" name="opken1" type="java.lang.Short">
<column name="OPKENN1"/>
</property>
<property generated="never" lazy="false" name="opken2" type="java.lang.Short">
<column name="OPKENN2"/>
</property>
<property generated="never" lazy="false" name="opken3" type="java.lang.Short">
<column name="OPKENN3"/>
</property>
<property generated="never" lazy="false" name="totalAmount" type="java.lang.Double">
<column name="GESAMTBETRAG"/>
</property>
<property generated="never" lazy="false" name="startOfBenefit" type="java.lang.Long">
<column name="WERTVON"/>
</property>
<property generated="never" lazy="false" name="endOfZukValidity" type="java.lang.Long">
<column name="WERTBIS"/>
</property>
<property generated="never" lazy="false" name="proposalNumber" type="java.lang.String">
<column name="FREMDPOLNR"/>
</property>
<property generated="never" lazy="false" name="dueDate" type="java.util.Date">
<column name="BEZBIS"/>
</property>
<property generated="never" lazy="false" name="buyoutTerm" type="java.lang.String">
<column name="TEXT"/>
</property>
</class>
</hibernate-mapping>
TranscriptionBean
@Component
@Scope(value = "request")
public class TranscriptionBean extends BaseBean {
@Autowired
private SessionBean sessionBean;
@Autowired
private ZukService zukService;
private BenefitsSearchPrescriptionCriteria prescriptionCriteria = new BenefitsSearchPrescriptionCriteria(
DEFAULT_ORDER_PROPERTY);
public List<DuniversalBenefitsPrescription> getPrescriptions() {
List<DuniversalBenefitsPrescription> prescriptionList = new ArrayList<DuniversalBenefitsPrescription>();
final boolean criteriaSet = setSearchCriteria();
if (criteriaSet) {
prescriptionList = zukService.getListOfPrescriptions(prescriptionCriteria);
sessionBean.setItemsFound(prescriptionList.size());
checkSendEditedPeriod();
}
for (final DuniversalBenefitsPrescription transcription : prescriptionList) {
polNrs.add(transcription.getPolicyNumber());
}
return prescriptionList;
}
}
請顯示與stacktrace相關的內容,即'TranscriptionBean'和它所管理的實體。 –
@StéphaneNicoll我編輯了我的貼子,添加了一些相關的代碼。 – Zdend
@Zdend異常是由於您給出'Date'類型而不是'Long',我認爲可能在'BenefitsSearchPrescriptionCriteria'類中。並且不需要發佈任何信息,保持與異常相關的類。 – Rembo