休眠:参数值与预期类型不匹配?

编程入门 行业动态 更新时间:2024-10-23 10:30:25
本文介绍了休眠:参数值与预期类型不匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

List< MappingInstruction> result = emFactory.get() .createQuery(FROM+ MappingInstruction.class.getSimpleName()+c where c.mapping =:mapping, MappingInstruction.class).setParameter(mapping ,mappingInfo.getId())。getResultList();

我得到:

服务异常执行操作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();

更多推荐

休眠:参数值与预期类型不匹配?

本文发布于:2023-11-26 00:12:03,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不匹配   参数   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!