I have 2 maven projects that both share a common parent project (for common dependencies and such). The first one (P1) is where I keep my business model. The other (P2) is a service layer, that uses the model and the persistence functionality in P1.
P1 pom:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>P1</artifactId>
<version>0.0.1-SNAPSHOT</version>
...
P2 pom:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>P2</artifactId>
<version>0.0.1-SNAPSHOT</version>
...
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>P1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
When I run the unit tests of P1 in Eclipse (Run as... Junit test) OR in the terminal (mvn clean test) they all work just fine. However, when I run the unit tests of P2 they only run in Eclipse (Run as... Junit test). When using Maven the tests in P2 that uses the model of P1 fails.
I checked the class path, and the only 2 differences are
In Eclipse the path to P1 classes is to the target folder in P1 directory. In Maven the path is to my local repository (which should be ok because P1 is installed there)
In Eclipse the class path contains references to Java Development Tools JUnit Runtime Support
I have confirmed that files in P1/target matches the files in .m2/.../P1.jar - this includes the META-INF/persistence.xml.
The errors I get in the unit tests are of the same kind:
javax.jdo.JDODataStoreException: Cannot set long parameter: value = 1 for column "JOINTABLE_A_B.B_ID" : Invalid argument in JDBC call: parameter index out of range: 1
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:546)
at org.datanucleus.api.jdo.JDOTransaction.commit(JDOTransaction.java:171)
at com.mycompany.dao.TransactionalWork.execute(TransactionalWork.java:19)
at com.mycompany.dao.BasicDAO.save(BasicDAO.java:40)
at com.mycompany.service.ServiceHandler.handle(ServiceHandler.java:28)
at com.mycompany.service.ServiceHandler.handle(ServiceHandler.java:15)
at com.mycompany.service.ServiceHandlerTest.handling(ServiceHandlerTest.java:50)
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.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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
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.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
NestedThrowablesStackTrace:
java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 1
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.outOfRangeArgument(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.checkSetParameterIndex(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setLong(Unknown Source)
at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingPreparedStatement.setLong(DelegatingPreparedStatement.java:121)
at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingPreparedStatement.setLong(DelegatingPreparedStatement.java:121)
at org.datanucleus.store.rdbms.ParamLoggingPreparedStatement.setLong(ParamLoggingPreparedStatement.java:777)
at org.datanucleus.store.rdbms.mapping.datastore.BigIntRDBMSMapping.setLong(BigIntRDBMSMapping.java:125)
at org.datanucleus.store.rdbms.mapping.java.SingleFieldMapping.setLong(SingleFieldMapping.java:150)
at org.datanucleus.store.rdbms.mapping.AppIDObjectIdFieldManager.storeLongField(AppIDObjectIdFieldManager.java:197)
at org.datanucleus.state.AppIdObjectIdFieldConsumer.storeLongField(AppIdObjectIdFieldConsumer.java:72)
at com.mycompany.model.Entity.dnCopyKeyFieldsFromObjectId(Entity.java)
at org.datanucleus.api.jdo.JDOAdapter.copyKeyFieldsFromIdToObject(JDOAdapter.java:699)
at org.datanucleus.store.rdbms.mapping.java.PersistableMapping.setObjectAsValue(PersistableMapping.java:648)
at org.datanucleus.store.rdbms.mapping.java.PersistableMapping.setObject(PersistableMapping.java:323)
at org.datanucleus.store.rdbms.mapping.java.PersistableMapping.setObject(PersistableMapping.java:302)
at org.datanucleus.store.rdbms.scostore.JoinSetStore.iterator(JoinSetStore.java:906)
at org.datanucleus.store.types.wrappers.backed.Set.loadFromStore(Set.java:320)
at org.datanucleus.store.types.wrappers.backed.Set.iterator(Set.java:485)
at org.datanucleus.store.fieldmanager.LoadFieldManager.internalFetchObjectField(LoadFieldManager.java:102)
at org.datanucleus.store.fieldmanager.AbstractFetchDepthFieldManager.fetchObjectField(AbstractFetchDepthFieldManager.java:105)
at org.datanucleus.state.AbstractStateManager.replacingObjectField(AbstractStateManager.java:1590)
at org.datanucleus.state.StateManagerImpl.replacingObjectField(StateManagerImpl.java:117)
at com.mycompany.model.Profile.dnReplaceField(Profile.java)
at com.mycompany.model.Entity.dnReplaceFields(Entity.java)
at org.datanucleus.state.StateManagerImpl.replaceFields(StateManagerImpl.java:3131)
at org.datanucleus.state.StateManagerImpl.replaceFields(StateManagerImpl.java:3158)
at org.datanucleus.state.AbstractStateManager.loadFieldsInFetchPlan(AbstractStateManager.java:1096)
at org.datanucleus.ExecutionContextImpl.performDetachAllOnTxnEndPreparation(ExecutionContextImpl.java:4460)
at org.datanucleus.ExecutionContextImpl.preCommit(ExecutionContextImpl.java:4115)
at org.datanucleus.ExecutionContextImpl.transactionPreCommit(ExecutionContextImpl.java:683)
at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:388)
at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:277)
at org.datanucleus.api.jdo.JDOTransaction.commit(JDOTransaction.java:107)
at com.mycompany.dao.TransactionalWork.execute(TransactionalWork.java:19)
at com.mycompany.dao.BasicDAO.save(BasicDAO.java:40)
at com.mycompany.service.ServiceHandler.handle(ServiceHandler.java:28)
at com.mycompany.service.ServiceHandler.handle(ServiceHandler.java:15)
at com.mycompany.service.ServiceHandlerTest.handling(ServiceHandlerTest.java:50)
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.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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
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.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
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.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.hsqldb.HsqlException: Invalid argument in JDBC call: parameter index out of range: 1
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
... 69 more
I use HyperSQL DB for my unit tests.
Has anyone experienced this problem and come up with a solution?
It turned out that due to the fact that I did not state my classes in my persistence.xml Datanucleus was scanning the classpath. This works great in Maven when running P1 because the classes are not stashed away in a jar file. In P2 however, the scan did not successfully find the classes even though the jar file was on the classpath. This is not the case in Eclipse because the reference to P1 is considered a project reference - hence classes are not placed jar file.