简体   繁体   English

entityManager.createNativeQuery 不返回输入结果

[英]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.

相关问题 如何不替换EntityManager.createNativeQuery()中的命名参数? - How to not replace named parameters in EntityManager.createNativeQuery()? HIBERNATE:TransactionRequiredException:在entityManager.createNativeQuery()之后执行更新/删除查询 - HIBERNATE : TransactionRequiredException: Executing an update/delete query after entityManager.createNativeQuery() 使用entityManager.createNativeQuery(query,foo.class) - use of entityManager.createNativeQuery(query,foo.class) EntityManager.createNativeQuery 在使用分页时返回对象列表而不是 BigDecimal 列表 - EntityManager.createNativeQuery returning list of objects instead of list of BigDecimal when using Pagination EntityManager createNativeQuery 在 Java Springboot 中返回错误的结果集 - EntityManager createNativeQuery returning wrong result set in Java Springboot 为什么EntityManager createNativeQuery列表有时返回BigDecimal而其他时候返回Integer? - Why EntityManager createNativeQuery lists sometimes return a BigDecimal and other times an Integer? 实体管理器JPA的createNativeQuery出现setParameter问题 - setParameter issue with createNativeQuery of entityManager JPA 在 JPA EntityManager createNativeQuery 中实现分页 - Implementing pagination in JPA EntityManager createNativeQuery EntityManager :: getDelegate返回什么? - What does EntityManager::getDelegate return? Hibernate CreateNativeQuery返回空列表 - Hibernate CreateNativeQuery return empty list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM