2017-05-18 1 views
0

ich versucht habe:JPA oder EntityManager Deal mit Liste der Parameter: Liste <Long>

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

ich: wie in Klammern x:

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

Ich habe auch zu setzen versucht (: x)

ich habe auch versucht

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

Und auch:

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(); 
} 

Ich habe immer noch die gleiche Stacktrace. Ich benutze Postgres 9.4 Irgendwelche Hilfe bitte?

Antwort

1

Sieht aus wie es fehlschlägt, wenn die Liste der Zeichenfolge leer ist.

Versuchen Sie, vor dem Abfrageaufruf eine Prüfung hinzuzufügen.

if (strings == null || strings.size() == 0) { 
    return new ArrayList(); 
} 
+0

Sie hatten Recht. Ich dachte, wenn Null der zurückgegebene Wert wäre null. Ich habe kein Versagen erwartet. Danke. – John

Verwandte Themen