In Jdbi3, how can I use bindBean() for same field?

216 Views Asked by At

I have Java code:

String updateSql = "UPDATE table_name SET field_two = :field_two"
                + " WHERE field_one = :field_one AND field_two <> :field_two"; 
handle.createUpdate(updateSql)
    .bindBean(myBean)
    .execute();
@Data
public class MyBean() {
   private String fieldOne;
   private String fieldTwo;
}

When Jdbi tries to bind the field_two the second time, it throws UnableToCreateStatementException: Missing named parameter field_two in binding.

How can I bind the field_two appeared multiple times in the query using bindBean()?

1

There are 1 best solutions below

0
On BEST ANSWER

It turns out that the binding needs to have the same name with the field name:

String updateSql = "UPDATE table_name SET field_two = :fieldTwo"
                + " WHERE field_one = :fieldOne AND field_two <> :fieldTwo";