eclipselink - Column type not valid with NATIVE query jpql -


this repository:

@repository public interface eventrepository extends jparepository<events, long>, jpaspecificationexecutor<events>{      @query(value=" select distinct event.event_id "                 + "from events event "                 + "join events event2 "                 + "on event.event_id = event2.parent_id "                 + "where event.entity_id in (?1)", nativequery = true)     list<long> getdescendanteventidinentityid(set<long> descendantentities); } 

why when method called, it's return: internal exception: java.sql.sqlexception: tipo di colonna non valido error code: 17004 call: select distinct event.event_id events event join events event2 on event.event_id = event2.parent_id event.entity_id in (?) bind => [[1]]

what wrong query? if query ok, "bind => [[1]]" true problem? if yes, why there's many square brackets?

i've tried solution:

@query(value=" select distinct event2.event_id "                 + "from events event "                 + "join events event2 "                 + "on event.event_id = event2.parent_id "                 + "where event.entity_id in :entitiesid", nativequery = true)     list<long> getdescendanteventidinentityid(@param("entitiesid") set<long> entitiesid); 

but return me error: missing in or out parameter @ index:: 1 error code: 17041 call: select distinct event2.event_id events event join events event2 on event.event_id = event2.parent_id event.entity_id in :entitiesid

solution: solved creating new nativequery entitymanager:

em.createnativequery(" select distinct event2.event_id "                                         + "from events event "                                         + "join events event2 "                                         + "on event.event_id = event2.parent_id "                                         + "where event.entity_id in ("+idlist+") , event.status = 2")                                           .getresultlist(); 

where idlist string made stringutils.join(collectionofid, ",");

if hibernate used jpa provider, instead of positional parameter binding (?1) use named parameter binding (:parametername). less error prone , omit brackets , let spring manage syntax your. not need parse on own.

use named parameter binding like:

@query(value="select distinct event2.event_id "         + "from events event "         + "join events event2 "         + "on event.event_id = event2.parent_id "         + "where event.entity_id in :entityids", nativequery = true) list<long> getdescendanteventidinentityid(@param("entityids") set<long> ids); 

be aware of passing null or empty set method, in both cases! cause unpredictable results.

sadly, named parameters not jpa standard , maybe eclipselink not support (in way). have go positional parameters.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -