[英]entityManager.createNativeQuery does not return a typed result
I need select native query with entityManager .我需要使用entityManager选择本机查询。 I found method:
我找到了方法:
public Query createNativeQuery(String sqlString, Class resultClass);
And try use it:并尝试使用它:
Query query = em.createNativeQuery(readyQuery, SmevMessage.class);
return query.getResultList();
But IDE still highlights as a warning:但是 IDE 仍然突出显示为警告:
Why then does this method exist?那么为什么会存在这种方法呢? and what should i do to fix it?
我该怎么做才能解决它?
Which warning do you get?你得到哪个警告? Does your IDE only warn you about the unchecked conversion of the returned
List
?您的 IDE 是否只警告您返回
List
的未经检查的转换?
You can ignore that one.你可以忽略那个。 Unfortunately, the
createNativeQuery
method returns an untyped Query
.不幸的是,
createNativeQuery
方法返回一个无类型的Query
。 There is no way you can fix that warning.您无法修复该警告。 If it really bothers you, you can suppress it with
@SuppressWarnings("unchecked")
.如果它真的困扰你,你可以用
@SuppressWarnings("unchecked")
抑制它。
And please be aware that you need to provide an entity class as the value of the resultClass
parameter, as I explained here .请注意,您需要提供一个实体类作为
resultClass
参数的值,正如我在此处解释的那样。 So, in your case, SmevMessage
has to be an entity.因此,在您的情况下,
SmevMessage
必须是一个实体。 If you want to map your query result to a DTO, you need to define an @SqlResultSetMapping
.如果要将查询结果映射到 DTO,则需要定义一个
@SqlResultSetMapping
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.