我认为我可以在我的 spring 对象中使用 entitymanager 的方法 persist 来坚持。其实我用的是spring roo。但是当我从数据库中获取一个对象时,我不能这样做:
object.persist(); // <--- it doesn't work
有谁知道为什么?我在哪里可以找到文档?
我得到了这个例外:
org.springframework.orm.jpa.JpaSystemException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.movi.duckury.server.domain.LoginLog; nested exception is javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.movi.duckury.server.domain.LoginLog
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:311)
at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
at com.movi.duckury.server.domain.LoginLog_Roo_Entity.ajc$interMethod$com_movi_duckury_server_domain_LoginLog_Roo_Entity$com_movi_duckury_server_domain_LoginLog$persist(LoginLog_Roo_Entity.aj:54)
at com.movi.duckury.server.domain.LoginLog.persist(LoginLog.java:1)
at com.movi.duckury.server.domain.LoginLog_Roo_Entity.ajc$interMethodDispatch1$com_movi_duckury_server_domain_LoginLog_Roo_Entity$com_movi_duckury_server_domain_LoginLog$persist(LoginLog_Roo_Entity.aj)
at com.movi.duckury.server.web.LoginLogControllerTest.findLoginLogsBySessionIdTest(LoginLogControllerTest.java:101)
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:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
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:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
引起:javax.persistence.PersistenceException:org.hibernate.PersistentObjectException:分离实体传递给持久化:com.movi.duckury.server.domain.LoginLog at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) 在 org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153) 在 org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678)在 sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:601) 在 org.springframework.orm .jpa。SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) at sun.proxy.$Proxy54.persist(Unknown Source) ... 34 更多原因:org.hibernate.PersistentObjectException:分离的实体传递给持久化:com.movi.duckury .server.domain.LoginLog at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) at org.hibernate.impl .SessionImpl.firePersist(SessionImpl.java:808) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate。 ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 还有 39 个在 sun.proxy.$Proxy54.persist(Unknown Source) 处调用(SharedEntityManagerCreator.java:240)... 34 更多原因:org.hibernate.PersistentObjectException:分离的实体传递给坚持:com.movi.duckury.server.domain .LoginLog at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) at org.hibernate.impl.SessionImpl.firePersist (SessionImpl.java:808) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate.ejb.AbstractEntityManagerImpl。坚持(AbstractEntityManagerImpl.java:672)... 39 更多在 sun.proxy.$Proxy54.persist(Unknown Source) 处调用(SharedEntityManagerCreator.java:240)... 34 更多原因:org.hibernate.PersistentObjectException:分离的实体传递给坚持:com.movi.duckury.server.domain .LoginLog at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) at org.hibernate.impl.SessionImpl.firePersist (SessionImpl.java:808) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate.ejb.AbstractEntityManagerImpl。坚持(AbstractEntityManagerImpl.java:672)... 39 更多34 更多原因:org.hibernate.PersistentObjectException:分离实体传递给持久化:com.movi.duckury.server.domain.LoginLog at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) at org. hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 还有 39 个34 更多原因:org.hibernate.PersistentObjectException:分离实体传递给持久化:com.movi.duckury.server.domain.LoginLog at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) at org. hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 还有 39 个onPersist(DefaultPersistEventListener.java:127) 在 org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) 在 org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808) 在 org.hibernate.impl .SessionImpl.persist(SessionImpl.java:782) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 还有 39 个onPersist(DefaultPersistEventListener.java:127) 在 org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61) 在 org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808) 在 org.hibernate.impl .SessionImpl.persist(SessionImpl.java:782) 在 org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 在 org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 还有 39 个AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 39 更多AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 39 更多
谢谢。