JPA:detached entity passed to persist

简介:
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的值,然而,实体类上面,注解处又标记了主键的生成策略,因此产生冲突。去掉之一即可。

wKiom1eE8gDSaEJaAABmp5C9fJE505.jpg-wh_50





 本文转自 w156445045 51CTO博客,原文链接:http://blog.51cto.com/enetq/1825861,如需转载请自行联系原作者

相关文章
|
6月前
|
缓存 关系型数据库 MySQL
【异常解决】缓存报错:Null key returned for cache operation (maybe you are using named params on classes withou
【异常解决】缓存报错:Null key returned for cache operation (maybe you are using named params on classes withou
200 0
Duplicate methods named spliterator with the parameters () and () are inherited from the types Colle
Duplicate methods named spliterator with the parameters () and () are inherited from the types Colle
49 0
|
应用服务中间件 Android开发
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
105 0
a configuration error occurred during startup. place verify the preference field whth the prompt:TomcatJDK name:
|
关系型数据库 MySQL 数据安全/隐私保护
Could not obtain connection to query metadata : Public Key Retrieval is not allowed
Could not obtain connection to query metadata : Public Key Retrieval is not allowed
464 0
2015-03-18 current note update logic in my task
2015-03-18 current note update logic in my task
72 0
2015-03-18 current note update logic in my task
How to give query view parameter values in APF
How to give query view parameter values in APF
How to give query view parameter values in APF
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
119 0
When should reread of cl_crm_bol_entity and $scope.$apply be called manually
component set load logic - why coms_pcat_bob is accessed during product search
component set load logic - why coms_pcat_bob is accessed during product search
111 0
component set load logic - why coms_pcat_bob is accessed during product search