加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

jpa – EclipseLink本机查询结果为POJO – [Class]的缺少描述符

发布时间:2020-12-14 16:35:19 所属栏目:Java 来源:网络整理
导读:我使用 EclipseLink来运行一些Native SQL.我需要将数据返回到POJO.我遵循 EclipseLink Docs的指示,但是我收到错误[Class]的描述符 查询列已被命名以匹配POJO的成员变量.我需要做一些附加的映射吗? POJO: public class AnnouncementRecipientsFlattenedDTO
我使用 EclipseLink来运行一些Native SQL.我需要将数据返回到POJO.我遵循 EclipseLink Docs的指示,但是我收到错误[Class]的描述符

查询列已被命名以匹配POJO的成员变量.我需要做一些附加的映射吗?

POJO:

public class AnnouncementRecipientsFlattenedDTO {

        private BigDecimal announcementId;
        private String recipientAddress;
        private String type;

        public AnnouncementRecipientsFlattenedDTO() {
            super();
        }

        public AnnouncementRecipientsFlattenedDTO(BigDecimal announcementId,String recipientAddress,String type) {
            super();
            this.announcementId = announcementId;
            this.recipientAddress = recipientAddress;
            this.type = type;
        }

    ... Getters/Setters

实体经理电话:

public List<AnnouncementRecipientsFlattenedDTO> getNormalizedRecipientsForAnnouncement(int announcementId) {
    Query query = em.createNamedQuery(AnnouncementDeliveryLog.FIND_NORMALIZED_RECIPIENTS_FOR_ANNOUNCEMENT,AnnouncementRecipientsFlattenedDTO.class);
    query.setParameter(1,announcementId);
    return query.getResultList();
}

解决方法

我发现您可以将本机查询执行的结果放入保存对象的数组列表中.然后可以遍历列表和Array元素并构建所需的Entity对象.
List<Object[]> rawResultList;

    Query query =
        em.createNamedQuery(AnnouncementDeliveryLog.FIND_NORMALIZED_RECIPIENTS_FOR_ANNOUNCEMENT);
    rawResultList = query.getResultList();

    for (Object[] resultElement : rawResultList) {
        AnnouncementDeliveryLog adl = new AnnouncementDeliveryLog(getAnnouncementById(announcementId),(String)resultElement[1],(String)resultElement[2],"TO_SEND");
        persistAnnouncementDeliveryLog(adl);
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读