Problem: Java mapper accessor num arguments must match num bind parameters

22 views
Skip to first unread message

Michael Stöckli

unread,
Jul 16, 2015, 3:59:54 AM7/16/15
to java-dri...@lists.datastax.com
Trying to use the Accessor interface to do a conditional update in the following way:

@Query("UPDATE users SET " +
            "email=:email," +
            "locale=:locale," +
            "created_time=:created_time," +
            "updated_time=:updated_time," +
            "verified_time=:verified_time," +
            "time_zone=:time_zone," +
            "status=:status," +
            "mobile_phone=:mobile_phone," +
            "full_name=:full_name " +
            "WHERE id=:id " +
            "IF email=:email AND mobile_phone=:mobile_phone")
    Statement updateUser(
            @Param("id") UUID id,
            @Param("email") String email,
            @Param("locale") String locale,
            @Param("created_time") Date createdTime,
            @Param("updated_time") Date updatedTime,
            @Param("verified_time") Date verifiedTime,
            @Param("time_zone") String timeZone,
            @Param("status") UserStatus status,
            @Param("mobile_phone") String mobilePhone,
            @Param("full_name") String fullName);

Get the following exception:
java.lang.IllegalArgumentException: The number of arguments for method updateUser (10) does not match the number of bind parameters in the @Query (12)

Both :email and :mobile_phone are repeated. 

This should work since we should have to set named bindings once, right?

Olivier Michallat

unread,
Jul 16, 2015, 6:06:17 AM7/16/15
to java-dri...@lists.datastax.com
Hi,

That's a bug. The driver compares with the number of bindings without taking into account duplicate names.

Could you create a ticket? Our issue tracker is at https://datastax-oss.atlassian.net/browse/JAVA

On a side note, why do you set email and phone again, given that you've already checked their value in the IF clause?

--

Olivier Michallat

Driver & tools engineer, DataStax


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Michael Stoeckli

unread,
Jul 16, 2015, 7:37:25 AM7/16/15
to java-dri...@lists.datastax.com
On Thu, Jul 16, 2015 at 12:06 PM, Olivier Michallat <olivier....@datastax.com> wrote:
Hi,

That's a bug. The driver compares with the number of bindings without taking into account duplicate names.

Could you create a ticket? Our issue tracker is at https://datastax-oss.atlassian.net/browse/JAVA

On a side note, why do you set email and phone again, given that you've already checked their value in the IF clause?

Good point. An oversight on my part.
Reply all
Reply to author
Forward
0 new messages