Jdbi: Strange behaviour with @Bind and @BindBean

Created on 10 Nov 2020  Β·  3Comments  Β·  Source: jdbi/jdbi

Hi all,

i don't know if this has beend already issued, since i did not find anything. If so, i am sorry to bother you guys.

We noticed in our team a strange behaviour for the following situation.
Our JDBI looks like

public interface DeviceRepository
{
    @RegisterBeanMapper(DeviceRowMapper.class)
    @SqlQuery(
            "SELECT * FROM myDeviceTable " +
            "WHERE name = :propertyEight " +
            "      AND devicePropertyOne = :propertyOne " +
            "      AND devicePropertyTwo = :propertyTwo " +
            "      AND devicePropertyThree =: propertyThree " +
            "      AND devicePropertyFour =: propertyFour"
            "      AND devicePropertyFive =: propertyFive"
            "      AND devicePropertySix =: propertySix"
            "      AND devicePropertySeven =: propertySeven"
            ")
      List<Device> findAllCurrentWith(
            @Bind String propertypropertyOneTwo,
            @Bind String propertypropertyThreeTwo,
            @Bind String propertyFour,
            @BindBean DeviceBean deviceBean
      );
}

And the Class DeviceBean looks something like

@Data
public final class DeviceRequestDto
{
    private String propertyTwo;
    private String propertyFive;
    private String propertySix;
    private String propertySeven;
    private String propertyEight;
}

Everything works fine on my machine with when testing it and in our pipeline the tests went all through as it was fine.

But here is the catch, on one of our teammembers machine the test or more specific the SQL Statements were not executed since an exception from the bindings were thrown.

2020-11-10 10:54:51,542 [http-nio-8081-exec-4] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/device] threw exception [Request processing failed; nested exception is org.jdbi.v3.core.statement.UnableToCreateStatementException: Missing named parameter 'propertyOne' in binding:{​​​​​​​positional:{​​​​​​​0:propertyOne,1:propertyThree,2:propertyFour}​​​​​​​, named:{​​​​​​​}​​​​​​​, finder:[{​​​​​​​lazy bean property arguments "DeviceBean(...)"}​​​​​​​]}​​​​​​​ [statement:SELECT * FROM myDeviceTable WHERE name = :customerNumber AND devicePropertyOne = :propertyOne AND devicePropertyTwo = :propertyTwo AND devicePropertyThree =: propertyThree AND devicePropertyFour =: propertyFour", arguments:{​​​​​​​positional:{​​​​​​​0:propertyOne,1:propertyThree,2:propertyFour}​​​​​​​​​​​​​​, named:{​​​​​​​}​​​​​​​, finder:[{​​​​​​​lazy bean property arguments "DeviceBean(...)"}​​​​​​​]}​​​​​​​]] with root cause
org.jdbi.v3.core.statement.UnableToCreateStatementException:  Missing named parameter 'propertyOne' in binding:{​​​​​​​positional:{​​​​​​​0:propertyOne,1:propertyThree,2:propertyFour}​​​​​​​, named:{​​​​​​​}​​​​​​​, finder:[{​​​​​​​lazy bean property arguments "DeviceBean(...)"}​​​​​​​]}​​​​​​​ [statement:SELECT * FROM myDeviceTable WHERE name = :customerNumber AND devicePropertyOne = :propertyOne AND devicePropertyTwo = :propertyTwo AND devicePropertyThree =: propertyThree AND devicePropertyFour =: propertyFour", arguments:{​​​​​​​positional:{​​​​​​​0:propertyOne,1:propertyThree,2:propertyFour}​​​​​​​​​​​​​​, named:{​​​​​​​}​​​​​​​, finder:[{​​​​​​​lazy bean property arguments "DeviceBean(...)"}​​​​​​​]}​​​​​​​]
    at org.jdbi.v3.core.statement.ArgumentBinder.missingNamedParameter(ArgumentBinder.java:147)

So the first instinct was then to bind additionally the sql parameters to the @Bind annotation.

  • before @Bind String propertyOne
  • after @Bind String("propertyOne") propertyOne.

Then the exception on my coworkers machine disappeared. Not exactly sure if this issue is from our side, but it was kind of strange to see it pass on my machine and the pipeline, but from a fresh master branch executed on my coworkers machine fail.

I just wanted to let you know if by any chance there might be a little improvement possible.

All 3 comments

Using @Bind without specifying the column name only works if you enable a compiler option that writes the parameter name to the class file, where Jdbi can read it out.

It sounds like your colleague needs to turn this on. Please read here: http://jdbi.org/#_compiling_with_parameter_names

Note also that the @Bind annotation becomes optional when that -parameters compiler option is used.

Okay, thank you for clarifing this @qualidafial .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Romqa picture Romqa  Β·  5Comments

mcarabolante picture mcarabolante  Β·  4Comments

agavrilov76 picture agavrilov76  Β·  5Comments

jarlah picture jarlah  Β·  3Comments

nonameplum picture nonameplum  Β·  5Comments