spring 事务配置 no matching editors or conversion strategy

org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy1] to required type

[com.brilliance.struts.service.impl.InvestServiceImpl] for property 'fundService'; nested exception is

java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy1] to required type

[com.brilliance.struts.service.impl.InvestServiceImpl] for property 'fundService': no matching editors orconversion strategy

found

在spring事务时会出现。
解决办法是:
在事务中加上下面语句
<property name="proxyTargetClass" >
   <value>true</value>
  </property>
表面proxy代理的是类而不是接口。

 

下面是我的事务配置:

 <bean id="transactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory"></ref>
   </property>
  </bean>
  <bean id="transactionAttributeSource"
   class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
   <property name="properties">
    <props>
     <prop key="*">PROPAGATION_REQUIRED, -Exeptions</prop>
    </props>
   </property>
  </bean>
  <bean id="abstractTxDefinition"
   class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
   lazy-init="true">
    <property name="proxyTargetClass" >
   <value>true</value>
  </property>
   <property name="transactionManager">
    <ref bean="transactionManager"></ref>
   </property>
   <property name="transactionAttributeSource">
    <ref bean="transactionAttributeSource"></ref>
   </property>
  </bean>

  <bean id="fundService1" parent="abstractTxDefinition">
   <property name="target">
    <ref bean="FundService"></ref>
   </property>
  </bean>

..............

<bean name="/updateFund"
  class="com.brilliance.struts.action.UpdateFundAction">
  <property name="fundService">
   <ref local="fundService1" />
  </property>
 </bean>

 原文地址 http://cache.baidu.com/c?m=9d78d513d99f1cb8589ccb2d4b478d3d450197634d80864e3989d30984642a1c0771e3ca7

















org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
 at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
 at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
 at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
 at com.zhjy.gea.module.affair.domain.Affair$$EnhancerByCGLIB$$e10be950.getAffairCatalogs(<generated>)
 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:585)
 at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2049) 
 at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1286)
 at org.apache.commons.beanutils.BeanUtilsBean.copyProperties(BeanUtilsBean.java:284)
 at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:137)

分析原因:
由于Spring控制的Hibernate的生命周期只针对数据层和服务层,而未管理到表现层,所以会出现the owning Session was closed的现象。针对这一点,我通过hibernate filter的方式来解决。

解决方法:
在web.xml中配置filter来解决。

Xml代码 
  1. <!--  hibernate session filter  -->   
  2.   < filter >   
  3.    < filter-name > hibernateFilter </ filter-name >   
  4.   
  5.   
  6.    < filter-class >    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter  
  7.    </ filter-class >   
  8.   </ filter >   
  9.    
  10.   
  11.   
  12.  < filter-mapping >   
  13.    < filter-name > hibernateFilter </ filter-name >   
  14.    < url-pattern > *.do </ url-pattern >   
  15.   </ filter-mapping >   

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值