Connecting to SQL databases using MyBatis
MyBatis is a persistence framework that maps SQL to Java objects. The MyBatis learning curve is flatter than JPA's and leverages on SQL, which makes it a good match if you have good knowledge about SQL or have many complex SQL queries you want to reuse.
As usual, you first need to add the dependency. Here is how to do it with Maven:
<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.5</version> </dependency>
Note
You can find the full implementation of the example developed in this section in the Data-centric-Applications-with-Vaadin-8/chapter-06/mybatis-example
Maven project.
Defining a database connection
With MyBatis, you can define a database connection using a Java API or a configuration XML file. The easiest way is to put an XML file in the classpath (the resources
directory, when using Maven). The following is an example of such a configuration file...