问题描述
List< MappingInstruction> result = emFactory.get()
.createQuery(FROM+ MappingInstruction.class.getSimpleName()+c where c.mapping =:mapping,
MappingInstruction.class).setParameter(mapping ,mappingInfo.getId())。getResultList();
我得到:
我在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:
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();
这篇关于休眠:参数值与预期类型不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!