Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can MyBatis create the database schema?

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.

like image 669
Sergio Trapiello Avatar asked Aug 13 '14 09:08

Sergio Trapiello


People also ask

What is the use of MyBatis?

MyBatis is an open source persistence framework which simplifies the implementation of database access in Java applications. It provides the support for custom SQL, stored procedures and different types of mapping relations. Simply put, it's an alternative to JDBC and Hibernate.

Is MyBatis an ORM?

MyBatis is a persistence framework – not ORM. It maps SQL statements to Java methods.

What is MyBatis generator?

MyBatis Generator (MBG) is a code generator for MyBatis MyBatis. It will generate code for all versions of MyBatis. It will introspect a database table (or many tables) and will generate artifacts that can be used to access the table(s).

What is dynamic SQL in MyBatis?

MyBatis Dynamic SQL allows you to dynamically specify a catalog and/or schema. This is useful for applications where the schema may change for different users or environments, or if you are using different schemas to shard the database.

How to create a new schema in MySQL?

In MySQL, the schema is the synonym for the database. Creating a new schema also means creating a new database. Fifth, the following window is open. You need to (1) enter the schema name, (2) change the character set and collation if necessary, and click the Apply button:

Does MyBatis support all of the free SQL statements?

I tried create a new database schema and new table via the mybatis, it works well with my mysql db. So it seems mybatis totally support the execution almost all of the free sql statement.

How to configure the environment of the database in MyBatis?

Within the environments element, we configure the environment of the database that we use in our application. In MyBatis, you can connect to multiple databases by configuring multiple environment elements. To configure the environment, we are provided with two sub tags namely transactionManager and dataSource.


1 Answers

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.

like image 195
Bogdan Avatar answered Sep 23 '22 12:09

Bogdan