0

I am using EclipseLink 2.5.2 and is using the following orm.xml to map the result of native query to POJOs.

<named-native-query name="RelSumView.findFmkItem">
    <query>
        select item_file_name
             , last_release_id
             , last_release_version
          from tableA
    </query>
</named-native-query>

<sql-result-set-mapping name="FmkItemDtoMapping">
    <constructor-result target-class="xxx.model.common.biz.dto.FmkItemDTO">
        <column name="item_file_name" class="java.lang.String" />
        <column name="last_release_id" class="java.lang.Integer" />
        <column name="last_release_version" class="java.lang.String" />
    </constructor-result>
</sql-result-set-mapping>

But in below DAO class:

public List<FmkItemDTO> getFmkReleaseItemsByEnvLabelId(int envLabelId) {
    return getEntityManager().createNamedQuery("RelSumView.findFmkItem", "FmkItemDtoMapping").getResultList();
}

The following exception is thrown:

Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-6042] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.QueryException

Exception Description: A session name must be specified for non-object-level queries. See the setSessionName(String) method.

Query: ResultSetMappingQuery(sql="RelSumView.findFmkItem")
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:480)
at xxx.model.common.dao.FmkReleaseDAO.getFmkReleaseItemsByEnvLabelId(FmkReleaseDAO.java:28)

I have no idea of what this exception is and on how to set the session name to the query.

Dicky Ho
  • 35
  • 6
  • You have a NAMED native query and are calling the WRONG method. `createNamedQuery` would make more sense to me ... –  Jun 15 '18 at 07:51
  • I have changed to `createNamedQuery` but still fails. – Dicky Ho Jun 16 '18 at 02:24
  • "still fails", and maybe when you tell us HOW, what exception, what stack trace? Because the partial trace you quote is NOT from use of createNamedQuery, since the "sql" is in the named query definition, NOT the name of the named query –  Jun 16 '18 at 08:38

0 Answers0