Mongodb 无效的参数索引!您似乎声明的查询方法参数太少了!-Spring Mongo文本搜索
我正在开发用于文本搜索的Mongodb 无效的参数索引!您似乎声明的查询方法参数太少了!-Spring Mongo文本搜索,mongodb,full-text-search,spring-data,spring-data-mongodb,text-search,Mongodb,Full Text Search,Spring Data,Spring Data Mongodb,Text Search,我正在开发用于文本搜索的Spring+Mongo数据JPA示例。当我尝试使用OrderID102进行搜索时。我希望所有记录都能从数据库中获取,这些记录在OrderID中包含102条。请帮助我,我看到以下错误即将发生 org.springframework.data.repository.query.ParameterOutOfBoundsException: Invalid parameter index! You seem to have declare too little query me
Spring+Mongo数据JPA
示例。当我尝试使用OrderID
102进行搜索时。我希望所有记录都能从数据库中获取,这些记录在OrderID
中包含102条。请帮助我,我看到以下错误即将发生
org.springframework.data.repository.query.ParameterOutOfBoundsException: Invalid parameter index! You seem to have declare too little query method parameters!
at org.springframework.data.repository.query.Parameters.getParameter(Parameters.java:178)
at org.springframework.data.repository.query.Parameters.getBindableParameter(Parameters.java:248)
at org.springframework.data.repository.query.ParametersParameterAccessor.getBindableValue(ParametersParameterAccessor.java:107)
at org.springframework.data.repository.query.ParametersParameterAccessor$BindableParameterIterator.next(ParametersParameterAccessor.java:165)
at org.springframework.data.mongodb.repository.query.ConvertingParameterAccessor$ConvertingIterator.next(ConvertingParameterAccessor.java:176)
at org.springframework.data.mongodb.repository.query.ConvertingParameterAccessor$ConvertingIterator.nextConverted(ConvertingParameterAccessor.java:185)
at org.springframework.data.mongodb.repository.query.MongoQueryCreator.from(MongoQueryCreator.java:244)
at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:114)
at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:58)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.createQuery(PartTreeMongoQuery.java:76)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:85)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:462)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy22.findByOrderId(Unknown Source)
at com.common.index.OrderTest.testOrderSearch(OrderTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:70)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
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:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
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:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at org.springframework.data.repository.query.Parameters.getParameter(Parameters.java:176)
... 52 more
我开发的代码:
Order.java
@Document(collection="orders")
public class Order {
@Id
private ObjectId id;
@Field("OrderID")
private Integer orderId;
@Field("CustomerID")
private String customerId;
@Field("EmployeeID")
private Integer employeeId;
@Field("OrderDate")
private String orderDate;
@Field("RequiredDate")
private String requiredDate;
@Field("ShippedDate")
private String shippedDate;
@Field("ShipVia")
private Integer shipVia;
@Field("Freight")
private Double freight;
@Field("ShipName")
private String shipName;
@Field("ShipAddress")
private Integer shipAddress;
@Field("ShipCity")
private String shipCity;
@Field("ShipRegion")
private String shipRegion;
@Field("ShipPostalCode")
private String shipPostalCode;
@Field("ShipCountry")
private Integer shipCountry;
@Field("field14")
private String field14;
// setters and getters
}
OrderRepository.java
public interface OrderRepository extends CrudRepository<Order, Integer>{
List<Order> findByOrderId(TextCriteria criteria);
}
OrderTest.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:application-config.xml"})
public class OrderTest {
private static final Logger LOGGER = LoggerFactory.getLogger(OrderTest.class);
@Autowired
private OrderRepository orderRepository;
@Test
public void testOrderSearch() {
TextCriteria criteria = TextCriteria.forDefaultLanguage().matchingAny("102");
List<Order> orders = orderRepository.findByOrderId(criteria);
System.out.println("Size : "+orders.size());
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(位置={“classpath:application config.xml”})
公共类顺序测试{
私有静态最终记录器Logger=LoggerFactory.getLogger(OrderTest.class);
@自动连线
专用医嘱存储库医嘱存储库;
@试验
public void testOrderSearch(){
TextCriteria=TextCriteria.forDefaultLanguage().matchingAny(“102”);
List orders=orderRepository.findByOrderId(标准);
System.out.println(“Size:+orders.Size());
}
}
application-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<context:annotation-config/>
<mvc:annotation-driven/>
<beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="locations">
<beans:list>
<beans:value>classpath:database.properties</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<context:component-scan base-package="com.common.model"/>
<!-- Default bean name is 'mongo' -->
<mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}"/>
<mongo:repositories base-package="com.common.repository"/>
<beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<beans:constructor-arg ref="mongo"/>
<beans:constructor-arg name="databaseName" value="${mongo.database.name}"/>
</beans:bean>
<beans:bean id="orderService" class="com.common.Service.OrderServiceImpl" />
</beans:beans>
classpath:database.properties
我已经提供了足够的信息。现在请帮忙。
方法列出findByOrderId(TextCriteria)
缺少域类型和查询方法声明中都存在的orderId所需的参数。
TextCriteria
参数是一个特殊参数,不会映射到方法声明的任何参数
从查询中删除OrderBy
,只需使用条件即可
List findAllBy(文本标准);
Hi Chris-我的经验是,我只能搜索字符串值,但不能搜索任何整数值。为什么?如何使用整数值进行搜索?我将尝试实现您的逻辑。是否可以获取所有包含OrderId以102开头的文档,如10210、10211、10213等?
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<context:annotation-config/>
<mvc:annotation-driven/>
<beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="locations">
<beans:list>
<beans:value>classpath:database.properties</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<context:component-scan base-package="com.common.model"/>
<!-- Default bean name is 'mongo' -->
<mongo:mongo id="mongo" host="${mongo.host}" port="${mongo.port}"/>
<mongo:repositories base-package="com.common.repository"/>
<beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<beans:constructor-arg ref="mongo"/>
<beans:constructor-arg name="databaseName" value="${mongo.database.name}"/>
</beans:bean>
<beans:bean id="orderService" class="com.common.Service.OrderServiceImpl" />
</beans:beans>