有没有人知道为什么测试会在使用ant运行时通过,但在使用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 :(得分:1)
该异常表示分离实体存在问题。 http://www.google.com.au/search?q=javax.persistence+detached+entity提出了许多关于分离实体的文件。
从其中一个文档 - “已分离 - 已分离的实体具有持久性标识,但它们当前未在持久性上下文中主动管理。”
由此我怀疑代码实际上存在问题,而不是Ant或maven。
答案 1 :(得分:1)
很可能ant build通过你的ant脚本和属性文件直接或通过你正在使用的ant任务设置环境的某种属性,而Maven构建不会这样做。
这反过来会让您在Maven中遇到不同的测试运行时配置但在Ant中失败。只是一个猜测,但我之前看到过;-)
答案 2 :(得分:1)
如果它与“预测试代码”没有运行相关,那么可以查看Maven故障安全插件并查看生命周期的前后集成测试阶段。
另外,Maven很可能使用与Ant不同的类路径 - 在它自己的本地仓库中引用JARS。值得注意的事情。
答案 3 :(得分:0)
在确定的防火配置中设置forkMode = never解决了问题。我不确定是什么原因,但如果没有这个选项,maven就没有运行ant的预测试代码。