My dependencies are:
springVersion = '3.2.4.RELEASE'
compile "org.springframework:spring-***:$springVersion"
*** = all of them are included just in case!
compile "org.springframework.data:spring-data-jpa:1.4.1.RELEASE"
compile "org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final"
runtime "org.hibernate:hibernate-entitymanager:4.2.6.Final"
testCompile "org.springframework:spring-test:$springVersion"
runtime "com.h2database:h2:1.3.173"
I have the following context file:
<tx:annotation-driven />
<jpa:repositories base-package="au.com.data3.samples.user.priv" />
<jdbc:embedded-database id="dataSource" type="H2">
</jdbc:embedded-database>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="au.com.data3.samples.user.model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="true" />
<property name="database" value="H2" />
</bean>
</property>
<property name="jpaProperties">
<props>
<!--<prop key="hibernate.max_fetch_depth"></prop>-->
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
I have my Repository class in the ....user.priv package:
public interface D3UserRepository extends JpaRepository<D3User, Long> {
D3User findByUsername(String username);
List<D3User> findByFirstName(String firstName);
List<D3User> findByLastName(String lastName);
List<D3User> findByFirstNameAndLastName(String lastName);
}
I have a Spring/JUnit test that has the following in it which causes the error:
@Autowired
private D3UserService mD3UserService;
The stacktrace is:
Caused by: java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(ArrayList.java:834) ~[na:1.7.0_40]
at org.springframework.data.jpa.repository.query.ParameterMetadataProvider.next(ParameterMetadataProvider.java:76) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:242) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:144) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryCreator.and(JpaQueryCreator.java:96) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryCreator.and(JpaQueryCreator.java:44) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:98) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:60) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:90) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68) ~[spring-data-jpa-1.3.5.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:279) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:147) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:153) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:43) ~[spring-data-commons-1.5.3.RELEASE.jar:na]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
... 83 common frames omitted
What am I doing wrong? I have tried many different things from similar posts but nothing has worked.
Please help.
If it is still of some help: You missed the second parmeter in
List<D3User> findByFirstNameAndLastName(String lastName);
It has to be
List<D3User> findByFirstNameAndLastName(String firstName, String lastName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With