记录org.springframework.beans.FatalBeanException:Could not copy property 'xxx' from source to target异常

Spring提供的BeanUtils.copyProperties()可以进行属性的拷贝,今天在做一个功能时将订单主表(OrdertMaster)里的属性拷贝到OrderDTO中时BeanUtils.copyProperties(orderMaster,orderDTO);报了异常,如下

org.springframework.beans.FatalBeanException: Could not copy property 'buyerAddress' from source to target; nested exception is java.lang.reflect.InvocationTargetException

    at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:690)
    at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:602)
    at com.xdtech.weisell.service.impl.OrderServiceImpl.findOne(OrderServiceImpl.java:111)
    at com.xdtech.weisell.service.impl.OrderServiceImpl$$FastClassBySpringCGLIB$$e3b16edc.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
    at com.xdtech.weisell.service.impl.OrderServiceImpl$$EnhancerBySpringCGLIB$$d6f874f7.findOne()
    at com.xdtech.weisell.service.impl.OrderServiceImplTest.findOne(OrderServiceImplTest.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:682)
    ... 37 more
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [com.xxxx.xxxx.dataobject.OrderMaster#1557719742516848694] - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:169)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:309)
    at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45)
    at org.hibernate.proxy.ProxyConfiguration$InterceptorDispatcher.intercept(ProxyConfiguration.java:95)
    at com.xdtech.weisell.dataobject.OrderMaster$HibernateProxy$XbHUYCUg.getBuyerAddress(Unknown Source)
    ... 42 more

异常提示不能将资源类(OrdertMaster)中的属性'buyerAddress’拷贝到目标类(OrdertDTO)中!!! 搜了下有人提示可能是source类中的属性和target类中的属性的类型不一致导致,提示不要使用基本类型要使用包装类。可我发现我的属性是String类型的,很显然这招可能对我不管用。。。突然偶向下看发现了这个Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [com.xxxx.xxxx.dataobject.OrderMaster#1557719742516848694] - no Session。嗦嘎,这不是前几天遇到的懒加载存在时,没有session的异常吗。当时是在source类上加了@Proxy(lazy=false)后解决了问题,于是偶激动的在OrderMaster上增加了@Proxy(lazy=false)这个注解和属性值。哟西!问题解决了!仅此记录下自己的填坑过程!

 

你可能感兴趣的:(使用JPA中的一些小麻烦)