微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我使用 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);
    }

原文地址:https://www.jb51.cc/java/124931.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐