The key component of MyBatis is SqlSessionFactory from which we get SqlSession and execute the mapped SQL statements. The SqlSessionFactory object can be created using XML-based configuration or Java API. The most commonly used approach for building…
As discussed in the previous chapter, MyBatis simplifies the persistent logic implementation by abstracting JDBC. MyBatis uses JDBC under the hood and provides simpler ways to implement database operations. When MyBatis executes an INSERT statement b…
In the SQL Mapper configuration file, we need to give the fully qualified name of the JavaBeans for the resultType and parameterType attributes. An example is as follows: <select id="findStudentById" parameterType="int" resultType=&…
The default MyBatis global settings, which can be overridden to better suit application-specific needs, are as follows: <settings> <setting name="cacheEnabled" value="true"/> <setting name="lazyLoadingEnabled"…
The properties configuration element can be used to externalize the configuration values into a properties file and use the properties' key names as placeholders. In the preceding configuration, we have externalized the database connection properties…
Mapper XML files contain the mapped SQL statements that will be executed by the application using statement id. We need to configure the locations of the SQL Mapper files in mybatis-config.xml. <mappers> <mapper resource="com/mybatis3/mapper…