JPA – missing descriptor for the native query result of eclipse link POJO – [class]

I use eclipse link to run some native SQL I need to return the data to POJO I followed the instructions of eclipse link docs, but I received the wrong descriptor of [class]

The query column has been named to match the member variables of the POJO Do I need to do some additional mapping?

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

Entity manager Tel:

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();
}

Solution

I found that you can put the results of native query execution into the array list of saved objects You can then traverse the list and array elements and build the required entity object

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);
    }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>