嗨,我收到以下错误。
java.lang.IllegalArgumentException: 未知参数位置: 1] 与根本原因 java.lang.IllegalArgumentException: 未知参数 位置: 1 在 org.hibernate.query.internal.QueryParameterBindingsImpl.getBinding(QueryParameterBindingsImpl.java:240( 在 org.hibernate.query.internal.AbstractProduceQuery.setParameter(AbstractProduceQuery.java:503( 在 org.hibernate.query.internal.AbstractProduceQuery.setParameter(AbstractProduceQuery.java:104( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method( at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62( 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43( at java.lang.reflect.Method.invoke(Method.java:498( at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:372( at com.sun.proxy.$Proxy 63.setParameter(Unknown Source( at edu.zipcloud.cloudstreetmarket.core.daos.HistoricalIndexRepositoryImpl.findLastHistoric(HistoricalIndexRepositoryImpl.java:37( 在 edu.zipcloud.cloudstreetmarket.core.daos.HistoricalIndexRepositoryImpl.findLastIntraDay(HistoricalIndexRepositoryImpl.java:31( 在 edu.zipcloud.cloudstreetmarket.core.services.MarketServiceImpl.getLastDayIndexActivity(MarketServiceImpl.java:41( 在 edu.zipcloud.cloudstreetmarket.portal.controllers.DefaultController.fallBack(DefaultController.java:26( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method( at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62( 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43( at java.lang.reflect.Method.invoke(Method.java:498( at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205( 在 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133( 在 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97( 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827( 在 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738( 在 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85( 在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967( 在 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901( 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970( 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861( at javax.servlet.http.HttpServlet.service(HttpServlet.java:622( at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846( at javax.servlet.http.HttpServlet.service(HttpServlet.java:729(
内部方法findLastHistoric(HistoricalIndexRepositoryImpl.java:37)
.class:
@Repository
public class HistoricalIndexRepositoryImpl implements HistoricalIndexRepository{
@PersistenceContext
private EntityManager em;
@Override
public Iterable<HistoricalIndex> findIntraDay(String code, Date of) {
TypedQuery<HistoricalIndex> sqlQuery = em.createQuery("from HistoricalIndex h where h.index.code = ? and h.fromDate >= ? and h.toDate <= ? ORDER BY h.toDate asc", HistoricalIndex.class);
sqlQuery.setParameter(1, code);
sqlQuery.setParameter(2, DateUtil.getStartOfDay(of));
sqlQuery.setParameter(3, DateUtil.getEndOfDay(of));
return sqlQuery.getResultList();
}
@Override
public Iterable<HistoricalIndex> findLastIntraDay(String code) {
return findIntraDay(code, findLastHistoric(code).getToDate());
}
@Override
public HistoricalIndex findLastHistoric(String code){
TypedQuery<HistoricalIndex> sqlQuery = em.createQuery("from HistoricalIndex h where h.index.code = ? ORDER BY h.toDate desc", HistoricalIndex.class);
sqlQuery.setParameter(1, code);
return sqlQuery.setMaxResults(1).getSingleResult();
}
}
请帮助我解决此错误。如果您需要其他信息,请告诉我。
问候。
这个怎么样?
TypedQuery<HistoricalIndex> sqlQuery = em.createQuery("from HistoricalIndex h where h.index.code = ?1 ORDER BY h.toDate desc", HistoricalIndex.class);
请在此处查看第 5.3.2 节。查询创建