Search code examples
javajdbi

What is the difference between @Bind and @BindBean in JDBI?


What is the difference between @Bind and @BindBean in JDBI?

Example code:

@SqlUpdate("insert into myObject (id, name) values (:id, :name)")
int insert(@BindBean MyObject myObject);

@SqlQuery("select id, name from myObject where id = :id")
MyObject findById(@Bind("id") long id);

Solution

  • From JDBI docs

    The @Bind annotation binds a single named argument. If no value is specified for the annotation it will bind the argument to the name it.

    and

    The @BindBean annotation binds JavaBeans™ properties by name. If no value is given to the annotation the bean properties will be bound directly to their property names. If a value is given, the properties will be prefixed by the value given and a period.