Newer
Older
labs / tiddlers / content / labs / lab07 / _Labs_07_Examine the SampleJdbiDAO Class.md
@Mark George Mark George on 3 Sep 889 bytes Lab 7
  1. Open the SampleJdbiDAO class. Again, this class has the same methods as the JDBC equivalent, but this class is using JDBI.

  2. Take a look at the getSamples method. The SQL for this method is currently blank --- copy the SQL that you used for the getSamples method in the JDBC DAO into the createQuery method parameter.

  3. Examine the getSamples method. This is significantly less code than the JDBC version.

    There is a mapToBean(Sample.class) call for creating the Sample object, but where is the Scientist being created?

    Take a look at the Sample class in the domain package. Look at lines 50 and 55 --- the @Nested annotation is doing the magic here. When creating the Sample object, JDBI will notice the @Nested annotation and will take that as a hint to also create a Scientist object and add it to the Sample via the setScientist method.