Can MyBatis create the database schema?

2020-07-09 09:50发布

问题:

Has MyBatis any feature to allow create the SQL schema from de Class Model like Hibernate does?

I'm looking for that in Google and I only found information about MyBatis Generator (http://mybatis.github.io/generator/). This tool seems to be useful for generate the Java model from the SQL Schema, which is just the opposite I want.

回答1:

Can MyBatis create the database schema?

I'm afraid not. In order to do that you need an ORM and MyBatis is not an ORM.

With an ORM solution (like Hibernate for example) you map tables to entities. The entity is the (object) representation of the (relational) table and contains all the metadata (getters/setters, annotations etc) necessary to create the table.

MyBatis does not map entities to tables, it maps methods to SQL statements. There is no way to determine from the methods or the SQL statements what the structure of the database should be. When you use MyBatis the tables must already exist.