1

I have tried :

@Query("Select m.id from Cars m where m.id not in :x")
List<Long> findNotChoosenCars(@Param("x") List<Long> CarsId);

I get :

org.postgresql.util.PSQLException: ERREUR: erreur de syntaxe sur ou près de « ) »
Translation: syntax error near << ) >>

I have also tried to put :x in brackets like : (:x)

I have also tried

@Query(value = "Select id from Cars where id not in (?1)",nativeQuery = true)
List<Long> findNotChoosenCars(List<Long> CarsId);

And also:

   private EntityManagerFactory emf;
   private List<Long> getNotSelectedCarsIds(List<Long> selectedIds){

    List<String>strings=selectedIds.stream().map(Object::toString).collect(Collectors.toList());
    final String notSelectedCarIdsSql= "Select id from Car where id not in (:strings)";
    return emf.createEntityManager().createNativeQuery(notSelectedMarkerIdsSql)
            .setParameter("strings",strings)
            .getResultList();
}

I still have the same stacktrace. I'm using postgres 9.4 Any help please ?

John
  • 185
  • 1
  • 6
  • 21

1 Answers1

2

Looks like it fails when the list of string is empty.

Try to add a check before the query call.

if (strings == null || strings.size() == 0) {
    return new ArrayList();
}
StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • You were right. I thought if null the returned value would be null. I didn't expect a fail.. Thank you. – John May 18 '17 at 10:00