JDBI bindMethodsList()/bindBeanList() throws UnableToCreateStatementException

104 Views Asked by At

I am trying to bind a list of tuples in JDBI:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class AuthorBooks {
    @EqualsAndHashCode.Include
    public long authorId;
    @EqualsAndHashCode.Include
    public long bookId;
}

Using bindMethodsList():

List<AuthorBooks> allAuthorBooks = Arrays.asList(new AuthorBooks(4394, 9977));
handler.createUpdate("DELETE FROM TABLE WHERE (author_id, book_id)"
                + " IS NOT IN (<allAuthorBooks>)")
      .bindMethodsList("allAuthorBooks", allAuthorBooks, List.of("getAuthorId, getBookId"))
      .execute();

Using bindBeanList():

List<AuthorBooks> allAuthorBooks = Arrays.asList(new AuthorBooks(4394, 9977));
handler.createUpdate("DELETE FROM TABLE WHERE (author_id, book_id)"
                + " IS NOT IN (<allAuthorBooks>)")
      .bindBeanList("allAuthorBooks", allAuthorBooks, List.of("authorId, bookId"))
      .execute();

Both approach throws error

org.jdbi.v3.core.statement.UnableToCreateStatementException: Unable to get getAuthorId, getBookId argument for AuthorBooks(authorId=4394, bookId=9977)

1

There are 1 best solutions below

0
On

For your attempt at bindMethodsList(), you need to actually add the getAuthorId() and getBookId() as public methods on your AuthorBooks class.

I'm not entirely sure what the issue is with your bindBeanList() implementation, but if you edit your question to include the specific error message, I'm happy to take a look.