本文共 3475 字,大约阅读时间需要 11 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.example.entity.UserInfo at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java: 124 ) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java: 58 ) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java: 778 ) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java: 751 ) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java: 756 ) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java: 1146 ) 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 org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java: 344 ) at com.sun.proxy.$Proxy44.persist(Unknown Source) 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 org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java: 294 ) at com.sun.proxy.$Proxy44.persist(Unknown Source) at com.example.service.impl.UserInfoServiceImpl.saveUser(UserInfoServiceImpl.java: 23 ) 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 org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java: 503 ) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java: 478 ) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java: 460 ) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java: 179 ) at org.springframework.transaction.interceptor.TransactionInterceptor$ 1 .proceedWithInvocation(TransactionInterceptor.java: 99 ) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java: 281 ) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java: 96 ) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java: 179 ) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java: 136 ) ... 81 common frames omitted |
产生这个现象的原因是:程序里面显示的微UserInfo这个对象设置的id的值,然而,实体类上面,注解处又标记了主键的生成策略,因此产生冲突。去掉之一即可。
本文转自 w156445045 51CTO博客,原文链接:http://blog.51cto.com/enetq/1825861,如需转载请自行联系原作者