Open the SampleJdbiDAO
class. Again, this class has the same methods as the JDBC equivalent, but this class is using JDBI.
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.
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.