我正在使用Spring JPA通過Hibernate與Progress OpenEdge數據庫進行通信。一切正常,但現在我試圖使用PagingAndSortingRepository中的findAll(Iterable ID)方法從數據庫中獲取ItemDescription對象的選定列表,並且它似乎不起作用...org.springframework.dao.InvalidDataAccessApiUsageException當使用findAll(Iterable <ID> ID)方法
這是我的ItemDescription型號:
@Entity
@Table(name = "ArtOmsPAD", catalog = "MSOFTDB", schema = "PUB")
@IdClass(ItemDescriptionPK.class)
public class ItemDescription implements Serializable
{
private static final long serialVersionUID = 1L;
@Size(max = 10)
@Column(name = "ArtGrp", length = 10)
@Id
private String itemGroup;
@Size(max = 70)
@Column(name = "ArtSymb", length = 70)
@Id
private String itemSymbol;
@Size(max = 4)
@Column(name = "Taal", length = 4)
@Id
private String language;
@Size(max = 400)
@Column(name = "Oms", length = 400)
private String description;
@Column(name = "record_crc", precision = 17, scale = 2)
private BigDecimal recordCrc;
... (Getters/Setters)
}
而我的ID類...
public class ItemDescriptionPK implements Serializable
{
private String itemGroup;
private String itemSymbol;
private String language;
public ItemDescriptionPK()
{
}
public ItemDescriptionPK(String pItemGroup,
String pItemSymbol,
String pLanguage)
{
this.itemGroup = pItemGroup;
this.itemSymbol = pItemSymbol;
this.language = pLanguage;
}
... (Hashcode/Equals)
}
而服務類:
@Service("ItemDescriptionService")
public class ItemDescriptionService
{
@Autowired
private IItemDescriptionRepository itemDescriptionRepository;
public Iterable<ItemDescription> findAll(Iterable<ItemDescriptionPK> pItemDescriptionPK)
{
return itemDescriptionRepository.findAll(pItemDescriptionPK);
}
... (findOne method)
}
我建立與IDS因爲我想讀這樣的所有ItemDescription對象列表(這是在ReceiptDetail服務類...):
for (ReceiptDetail oReceiptDetail : lReceiptDetail)
{
oItemDescriptionPK = new ItemDescriptionPK(oReceiptDetail.getItemGroup(),
oReceiptDetail.getItemSymbol(),
vLanguage);
lItemDescriptionPK.add(oItemDescriptionPK);
}
事後我使用下面的代碼實際上閱讀ItemDescription對象:
itemDescriptionService.findAll(lItemDescriptionPK);
但是,這在執行時,我得到以下異常和堆棧跟蹤:
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [MSoftServlet] in context with path [/Receipt] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value element [itemGroup=12010,itemSymbol= 80 10100 -04 -000 -000,language=N] did not match expected type [java.lang.String (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value element [itemGroup=12010,itemSymbol= 80 10100 -04 -000 -000,language=N] did not match expected type [java.lang.String (n/a)]] with root cause
java.lang.IllegalArgumentException: Parameter value element [itemGroup=12010,itemSymbol= 80 10100 -04 -000 -000,language=N] did not match expected type [java.lang.String (n/a)]
at org.hibernate.jpa.spi.BaseQueryImpl.validateCollectionValuedParameterBinding(BaseQueryImpl.java:908)
at org.hibernate.jpa.spi.BaseQueryImpl.validateBinding(BaseQueryImpl.java:878)
at org.hibernate.jpa.internal.QueryImpl.access$000(QueryImpl.java:80)
at org.hibernate.jpa.internal.QueryImpl$ParameterRegistrationImpl.bindValue(QueryImpl.java:248)
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:631)
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:180)
at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.setParameter(CriteriaQueryTypeQueryAdapter.java:167)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:280)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:60)
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:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:358)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy150.findAll(Unknown Source)
at com.msoft.service.progress.ItemDescriptionService.findAll(ItemDescriptionService.java:48)
at com.msoft.service.progress.ReceiptDetailService.findByOfficeAndNumber(ReceiptDetailService.java:67)
at com.msoft.controller.progress.ReceiptDetailController.findByOfficeAndNumber(ReceiptDetailController.java:45)
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:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
如果我正確理解異常,我會認爲我的ItemDescriptionPK類中的某個元素具有錯誤的數據類型,但我沒有看到它的任何錯誤... ID的所有三個部分都被定義爲String(否則I如果有人可以告訴我我做錯了什麼,或者可以給我的指示我可以嘗試通過這個異常,我會是gratefull。就像旁邊一樣......因爲我只是在爲這個項目學習Java,所以我們仍然感覺我們的方法如此變化/方法/ ......根據最佳實踐,命名可能並不完整。這是我們仍然在我們的TODO名單上。
由於提前,
海諾
嗯,我必須將我的Id類中的字段映射到對象類中的相應字段不? findAll方法需要一個ItemDescriptionPK對象的迭代器作爲輸入參數,並且它會得到這些對象的一個列表(據我所知,它可以轉換爲一個迭代器)。有沒有辦法讓這個工作以某種方式? – HeinoVDS 2014-09-30 12:24:41
在您定義的組合鍵類型的類中創建一個字段。將itemGroup字符串中的@Id註釋更改爲新字段。 – 2014-09-30 12:36:51
好吧,這似乎是或多或少工作...如果我的ItemDescriptionRepository中有一個findBy,它使用了我的模型的一些關鍵字段,這不再有效(在我的情況下,我有一個findByItemGroupAndItemSymbol)。這些字段在模型中不再可用,但移動到PK類,現在我得到一個錯誤,說明該方法無法生成。所以,我想我以前的評論中的問題應該是,有沒有辦法讓這個工作,而不刪除在findBy方法中使用這些字段的選項? – HeinoVDS 2014-09-30 14:22:17