我正在使用Spring JPA通过Hibernate与Progress OpenEdge数据库进行通信。一切正常但现在我正在尝试使用PagingAndSortingRepository中的findAll(Iterable ids)方法从数据库中获取一个选定的ItemDescription对象列表,它似乎不起作用......
这是我的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)
}
我为所有想要读取的ItemDescription对象的id建立一个列表(这是在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(否则我会期望构造函数也抛出异常......)
所以,如果有人能告诉我我做错了什么,或者可以给我指示我可以尝试通过这个例外,我会感激不尽。就像旁边一样...因为我正在为这个项目学习Java,我们仍然感觉我们的方式如此变量/方法/ ...根据最佳实践,命名可能不完整。这是我们在TODO清单上仍然存在的东西..;
提前致谢,
海诺
答案 0 :(得分:0)
您在实体中定义了类型为java.lang.String的@Id
。所有休眠尝试都要将复合键映射到该列。