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,如需转载请自行联系原作者

相关文章
|
Serverless
attempt to delete a method
attempt to delete a method
202 1
|
6月前
|
JavaScript
Property “selectedItemIndex“ was accessed during render but is not defined on instance. 报错解决
Property “selectedItemIndex“ was accessed during render but is not defined on instance. 报错解决
594 0
|
缓存 关系型数据库 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
588 0
|
6月前
|
TensorFlow 算法框架/工具 Python
完美解决丨RuntimeError: create_session() called before __init__().
完美解决丨RuntimeError: create_session() called before __init__().
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
73 0
|
JavaScript
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-
Changing scope values asynchronously - updates don't propagate without .apply()
Changing scope values asynchronously - updates don't propagate without .apply()
Changing scope values asynchronously - updates don't propagate without .apply()
2015-03-18 current note update logic in my task
2015-03-18 current note update logic in my task
89 0
2015-03-18 current note update logic in my task
|
中间件
IBASE change and save - Middleware related
IBASE change and save - Middleware related
IBASE change and save - Middleware related