Because of performance issues with fetching about 30k results from DB as entities when using Hibernate JPA, i instead tried to write a namedQuery to have more control over the query and its runtime. What i end up with is almost 20 seconds just for those few entities, and those 20 seconds are necessary for the "old" query and my own namedQuery (which doesn't take a second to get the result when executed in a sql client), so basically it doesn't make any difference whether i use a namedQuery or the hibernate-generated query.
Is it safe to assume that 98% of the time is used for mapping those results to their corresponding entities? And if so, how should i speed this up? Below is the query that i wrote myself (note that i explicitly have to state all the columns in the SELECT)
SELECT exp.ID ,exp.CREATEDBY ,exp.CREATEDTIME ,exp.DELETED ,exp.LASTCHANGE ,exp.LASTCHANGEBY ,exp.STATUS ,exp.BRIXFIGURE ,exp.GRAMMAGE ,exp.INDIVIDUALPACKAGING ,exp.MINORDERQUANTITY ,exp.PACKAGINGHEIGHT ,exp.PACKAGINGLENGTH ,exp.PACKAGINGWIDTH ,exp.PALETTESIZE ,exp.QUANTITY ,exp.UNIT ,exp.VALIDUNTIL ,exp.EXPORTELEMENT_START ,exp.EXPORTSTATUS ,exp.webServiceResponse ,exp.CATEGORYID ,exp.COMMENTID ,exp.SUPPLIERID ,exp.TRANSPORTPACKAGINGID ,exp.LocationId ,exp.PriceRowId ,exp.EXPORTELEMENT_ENDDATE ,exp.BASEPRICE ,exp.BASEUNIT ,exp.BARCODES ,exp.EXPIRYDATE ,exp.PREORDERPERIOD ,exp.EXPORTWEEKID ,exp.EXPORT_TENDER_UID ,exp.EXPORT_UID ,exp.CURRENCY_ID ,exp.WEIGHT_PER_BOX FROM EXPORTELEMENT AS exp JOIN EXPORTELEMENT_LOCATION as exlo ON exlo.EXPORTELEMENTID = exp.ID WHERE exlo.LOCATIONID = :locationId AND exp.EXPORTELEMENT_ENDDATE <= :endDate AND exp.EXPORTELEMENT_START >= :startDate AND exp.DELETED = :deleted