this is my 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 this method is called, it's return: Internal Exception: java.sql.SQLException: Tipo di colonna non valido Error Code: 17004 Call: SELECT DISTINCT event.EVENT_ID FROM EVENTS event JOIN EVENTS event2 ON event.EVENT_ID = event2.PARENT_ID WHERE event.ENTITY_ID IN (?) bind => [[1]]
what is wrong with the query? If the query is ok, is that "bind => [[1]]" the true problem? If yes, why there's too many square brackets?
I've also tried this 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 it return me another error: Missing IN or OUT parameter at index:: 1 Error Code: 17041 Call: SELECT DISTINCT event2.EVENT_ID FROM EVENTS event JOIN EVENTS event2 ON event.EVENT_ID = event2.PARENT_ID WHERE event.ENTITY_ID IN :entitiesId
SOLUTION: Solved creating a new nativeQuery from 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+") AND event.STATUS = 2")
.getResultList();
Where idList is a String made by StringUtils.join(CollectionOfId, ",");