BTW i am using OpenJPA 2.4.2 (JPA 2.0)

strange but if i completely remove the result-set-mapping and simply use the resultClass parameter it works fine TypedQuery<CategoryYearResult> q = em.createNamedQuery("selectCategoryYear", CategoryYearResult.class);
List<CategoryYearResult> categoryYearResultList = q.getResultList();

i did use your suggestion of figuring out what types were being returned inside Object[] to tune the resultClass types

On 08/03/2018 13:46, Craig Taylor wrote:
Try using longs instead of integer.  If you grab the result set without
conversion you should be able to iterate through the list to see what is
being returned.

On Mar 8, 2018 07:38, "Matthew Broadhead" <matthew.broadh...@nbmlaw.co.uk>
wrote:

hi i am trying to do a NamedNativeQuery with a SqlResultSetMapping and i
get javax.el.ELException: java.lang.ClassCastException: [Ljava.lang.Object;
cannot be cast to uk.me.kissy.file.entities.categoryYear.CategoryYearResult.
is this type of operation not supported?
my orm.xml is
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1"
     xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"; xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance";
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd";>
     <entity class="uk.me.kissy.file.entities.jpa.File" name="File">
         <named-native-query name="selectCategoryYear"
             result-set-mapping="CategoryYearMapping">
             <query><![CDATA[select year(completiondate) as year,
categoryid, count(id) as count from conveyancing.file where completiondate
is not null and categoryid is not null group by year, categoryid order by
year;]]></query>
         </named-native-query>
         <sql-result-set-mapping name="CategoryYearMapping">
             <constructor-result
target-class="uk.me.kissy.file.entities.categoryYear.CategoryYearResult">
                 <column name="year" class="java.lang.Integer" />
                 <column name="categoryid" class="java.lang.Integer" />
                 <column name="count" class="java.lang.Integer" />
             </constructor-result>
         </sql-result-set-mapping>
     </entity>
</entity-mappings>


Reply via email to