休眠:参数值与预期类型不匹配? [英] Hibernate: Parameter value did not match expected type?

查看:266
本文介绍了休眠:参数值与预期类型不匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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]没有
匹配预期类型 [com。 vernuso.trust.server.domain.clientimport.MappingInfo(n / a)]


我在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();

这篇关于休眠:参数值与预期类型不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆