我得到:
服务异常执行操作MappingAddAction, java.lang.IllegalArgumentException:参数值[5118]没有匹配预期类型
我在Eclipse中调试过, mappingInfo.getId()确实返回5118。
有人可以帮我理解为什么期望类型为code> MappingInfo 而不是 long ?
如下图所示。 MappingInfo与MappingInstruction表有一对多的关系。
List< MappingInstruction> =h2_lin>解决方案
result = emFactory.get() .createQuery(FROM+ MappingInstruction.class.getSimpleName()+c where c.mapping =:mapping, MappingInstruction.class).setParameter(mapping ,mappingInfo.getId())。getResultList();
您从 MappingInstruction 实体中提取。在where条件中, c.mapping 是 MappingInfo 类型。请检查 MappingInstruction 类中映射变量的数据类型。
由于 c.mapping 类型为 MappingInfo ,但是您传递的是长的apache.lang. IllegalArgumentException 抛出的mappingInfo.getId()。
,更正如下:
列表< MappingInstruction> result = emFactory.get() .createQuery(FROM+ MappingInstruction.class.getSimpleName()+c where c.mapping =:mapping, MappingInstruction.class).setParameter(mapping ,mappingInfo).getResultList();
When I try to run:
List<MappingInstruction> result = emFactory.get() .createQuery("FROM " + MappingInstruction.class.getSimpleName() + " c where c.mapping = :mapping", MappingInstruction.class).setParameter("mapping", mappingInfo.getId()).getResultList();I get:
Service exception executing action "MappingAddAction", java.lang.IllegalArgumentException: Parameter value [5118] did not match expected type [com.vernuso.trust.server.domain.clientimport.MappingInfo (n/a)]
I debugged in Eclipse and mappingInfo.getId() does return 5118.
Can someone please help me understand why it expects the type MappingInfo instead of long?
I have two tables as shown in the image below. MappingInfo has One-To-Many relationship with MappingInstruction table.
解决方案Look closely:
List<MappingInstruction> result = emFactory.get() .createQuery("FROM " + MappingInstruction.class.getSimpleName() + " c where c.mapping = :mapping", MappingInstruction.class).setParameter("mapping", mappingInfo.getId()).getResultList();You are fetching from MappingInstruction Entity. In the where condition, c.mapping is of type MappingInfo. Please check the datatype of mapping variable inside MappingInstruction class.
Because c.mapping is of type MappingInfo,but you are passing mappingInfo.getId() which is long, the ava.lang.IllegalArgumentException throws.
So, Correction is as follows:
List<MappingInstruction> result = emFactory.get() .createQuery("FROM " + MappingInstruction.class.getSimpleName() + " c where c.mapping = :mapping", MappingInstruction.class).setParameter("mapping", mappingInfo).getResultList();
更多推荐
休眠:参数值与预期类型不匹配?
发布评论