olavloite / spanner-jdbc

JDBC Driver for Google Cloud Spanner
MIT License
38 stars 10 forks source link

Native query no parameter found for binding #81

Closed flascaray closed 6 years ago

flascaray commented 6 years ago

Hi, when I make a native query using Spring Data JPA I get the following error.

@Query(nativeQuery = true, value = "SELECT news.news_type_id FROM ("
            + "SELECT "
            + "n.news_type_id "
            + "FROM news2 AS n INNER JOIN news_types nt ON (nt.news_type_id = n.news_type_id) "
            + "WHERE n.seeker_id = :seekerId ) AS news LIMIT 1")
Map<String, String> findBySeekerId(@Param("seekerId") String seekerId);
Caused by: nl.topicus.jdbc.shaded.io.grpc.StatusRuntimeException: INVALID_ARGUMENT: No parameter found for binding: p1
    at nl.topicus.jdbc.shaded.io.grpc.Status.asRuntimeException(Status.java:526)
    ... 19 common frames omitted
olavloite commented 6 years ago

Fixed for version 1.0.10.

flascaray commented 6 years ago

Hi @olavloite i installed the new version but i have the same problem. The query is a little different:

@Query(nativeQuery = true, value = "SELECT news.news_type_id, news.text FROM ( "
            + "SELECT n.news_type_id, n.text, nt.enabled, nt.priority, nt.news_start, nt.news_end FROM news AS n INNER JOIN news_types nt ON nt.news_type_id = n.news_type_id WHERE n.seeker_id = :seekerId "
            + "UNION ALL "
            + "SELECT nt.news_type_id, nt.text, nt.enabled, nt.priority, nt.news_start, nt.news_end FROM news_types AS nt WHERE nt.type = 'SIMPLE'"
            + ") AS news "
            + "WHERE news.enabled = true "
            + "AND (news.news_start IS NULL OR news.news_start < CURRENT_TIMESTAMP()) "
            + "AND (news.news_end IS NULL OR news.news_end > CURRENT_TIMESTAMP()) "
            + "AND news.news_type_id NOT IN (:oldNews) "
            + "ORDER BY news.priority DESC "
            + "LIMIT 1 ")
Map<String, String> findBySeekerId(@Param("seekerId") String seekerId, @Param("oldNews") List<String> oldNews);
Caused by: nl.topicus.jdbc.shaded.io.grpc.StatusRuntimeException: INVALID_ARGUMENT: No parameter found for binding: p1
    at nl.topicus.jdbc.shaded.io.grpc.Status.asRuntimeException(Status.java:526)
    ... 19 common frames omitted

If i comment de UNION lines it's work

// + "UNION ALL "
// + "SELECT nt.news_type_id, nt.text, nt.enabled, nt.priority, nt.news_start, nt.news_end FROM news_types AS nt WHERE nt.type = 'SIMPLE'"