2010-12-17 93 views
0

有沒有人有任何想法爲什麼測試通過與螞蟻運行時,但失敗時運行與maven?當通過螞蟻運行時傳遞的測試,但通過maven運行時失敗?

我在Windows上運行我的測試,顯然有一些問題surefire和Windows?我試着改變useSystemClassLoader = False和useManifestOnlyJar = true,但一直未能讓他們工作。下面的堆棧是我在使用maven運行測試時遇到的錯誤。

我注意到的一件事是在堆棧中有$ Proxy.someMethod調用,我不知道它們來自哪裏。

感謝您的任何幫助。

javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: cheetah.entities.businessdata.Attribute 
     at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) 
     at $Proxy27.persist(Unknown Source) 
     at cheetah.repositories.businessdata.jpa.JpaAttributeRepository.create(JpaAttributeRepository.java:28) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
     at $Proxy29.create(Unknown Source) 
     at cheetah.tests.integration.util.BusinessDataLookupData.createAttributeLookupData(BusinessDataLookupData.java:19) 
     at cheetah.tests.integration.util.BusinessDataLookupData.create(BusinessDataLookupData.java:10) 
     at cheetah.tests.integration.util.LookupData.create(LookupData.java:7) 
     at cheetah.tests.integration.util.TestUtil.prepareData(TestUtil.java:23) 
     at cheetah.repositories.businessdata.tests.integration.AttributeRepositoryTest.setUpClass(AttributeRepositoryTest.java:23) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) 
     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
     at org.junit.runners.ParentRunner.run(ParentRunner.java:236) 
     at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59) 
     at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:120) 
     at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:103) 
     at org.apache.maven.surefire.Surefire.run(Surefire.java:169) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350) 
     at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021) 
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: cheetah.entities.businessdata.Attribute 
     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) 
     at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786) 
     at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) 
     ... 43 more 

回答

0

設置forkMode =從來沒有在肯定的火災配置解決了問題。我不確定推理的結果,但沒有這個選項,maven沒有運行螞蟻的預測試代碼。

1

異常表示分離的實體存在問題。 http://www.google.com.au/search?q=javax.persistence+detached+entity提出了許多關於分離實體的文檔。

從這些文檔之一 - 「分離 - 分離的實體具有持久性標識,但它們目前不在持久性上下文中進行主動管理。」

從此我懷疑實際上存在代碼問題,而不是Ant或maven。

+0

嗯,我想你可能是對的。我覺得很奇怪,測試通過了螞蟻,但不是在maven中。 – 2010-12-17 03:34:36

1

最有可能的是ant build通過你的ant腳本和屬性文件直接或者通過你正在使用的ant任務來設置某種環境屬性,而Maven構建不會這樣做。

這反過來讓你在Maven中失敗,但在Ant中失敗的測試運行時配置不同。只是一個猜測,但我看到之前;-)

1

如果它與'預測試代碼'沒有運行有關,那麼可以查看Maven故障安全插件並查看生命週期的前期和後期集成測試階段。

此外,Maven很可能使用了一個不同的類路徑到Ant - 在它自己的本地回購中引用JARS。需要注意的地方。

+0

+1感謝您的建議。我從來沒有意識到Surefire只能用於單元測試而不是集成測試 - 也許這就是我遇到這麼多問題的原因! – 2010-12-20 18:28:05

相關問題