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.